Array In VB.Net- By:-Sapan Das - .OnlineGuruji

.OnlineGuruji

Provides E-Notes,Video Tutorials And Download Links For Students In hindi

*********************************************************

*********************************************************
********************************************************************************

Breaking

Ramchandicollege Saraipali

Technology Jobs

OnlineGuru Blog मे आपका स्वागत है ब्लॉग से संबन्धित जानकारी के लिए संपर्क करें मो ॰ नम ।-9826026747(सपन कुमार दास) अपने विषय से संबन्धित अपडेट प्राप्त करने के लिए ब्लॉग पे दिये गए Bell Icon को press करें कम्प्युटर,Science,English Grammer से संबन्धित विषय की अधिक जानकारी के लिए हमारे ब्लॉग अथवा यू ट्यूब चैनल को सब्क्राइब करे ..

Monday, June 1, 2020

Array In VB.Net- By:-Sapan Das

Download Here:-Array



Introduction of Array:-

Array is collection of variables having same name  and  same data types with  unique index number and store in consicutive memory location

Declaration of Array:-

Dim Array_name(size) as data_Type

Example

Dim myarray(5) as integer

Memory Allowcation:-

Myarray(0)à Myarray(1)àMyarray(2)àMyarray(3)àMyarray(4)à

Initialization Of Array

Dim arrayname(optional) as data type={val-1,val-2,val-3,…..val-n}

Example

Dim myarray()as integer={45,88,66,87}

 

 

 

 

 

 




Public Class array

    Dim myarray() As Integer = {12, 85, 56, 45, 50}

    Dim namearray() As String = {"amitabh", "abhishekh", "jaya", "vijaya", "aishwarya"}

    Dim i As Integer

    Dim num(5) As Integer

    Dim count, sum As Integer

    Dim n As Integer

  Private Sub array_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ListBox1.Items.Add(myarray(0))

        ListBox1.Items.Add(myarray(1))

        ListBox1.Items.Add(myarray(2))

        ListBox1.Items.Add(myarray(3))

        ListBox1.Items.Add(myarray(4))

        ListBox1.Items.Add(namearray(0))

        ListBox1.Items.Add(namearray(1))

        ListBox1.Items.Add(namearray(2))

        ListBox1.Items.Add(namearray(3))

        ListBox1.Items.Add(namearray(4))

    End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ListBox1.Items.Clear()

        ListBox2.Items.Clear()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        For Me.i = 0 To 4

            ListBox1.Items.Add(myarray(Me.i))

            ListBox1.Items.Add(namearray(Me.i))

        Next

    End Sub







 Dim name() As String

         Dim x As Integer

        name(0) = "Niraj"

        name(1) = "Rameshwari"

        name(2) = "Badal"

 

        name(3) = "BadriNath"

        name(4) = "Padmini"

        For x = 0 To name.Length - 1

            MsgBox(name(x))

        Next

Dim name() as string= {“Mark”,”July”,”Patrik”,”Poul”,”John”}

For x=0 to 4

00           01  02

10     11  12

20     21  22

 Add items to two dim array

Public Class Form4

    Dim grid(2, 2) As Integer

    Dim r As Integer

    Dim c As Integer

       Private Sub Button1_Click()       

        For Me.r = 0 To 2

            For Me.c = 0 To 2

     grid(Me.r, Me.c) = InputBox("Enter Array Element")            Next

        Next

    End Sub

    Private Sub Button2_Click()

        Dim temp As String = ""

        For Me.r = 0 To 2

            For Me.c = 0 To 2

temp = temp & "   " & grid(Me.r,me.c).ToString()

            Next

            ListBox1.Items.Add(temp)

            temp = ""

        Next

    End Sub

     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        ListBox1.Items.Clear()

    End Sub

End Class  




00

01

10

11

20

21

 Private Sub Button4_Click()      

 ListBox1.Items.Clear()

        Dim A(2, 1) As Integer

        Dim i, k As Integer

        Dim outputline As String

        For i = 0 To 2

            outputline = ""

            For k = 0 To 1

    A(i, k) = InputBox("Enter Elemrnt")

         outputline &= A(i, k) & "  "

 

            Next k

            ListBox1.Items.Add(outputline)

        Next i

    End Sub




 Addition Of Array

Private Sub Button5_Click()      

 Dim grid1(2, 2), grid2(2, 2), grid3(2, 2) As Integer

        Dim r1 As Integer

        Dim c1 As Integer

        For r1 = 0 To 2

            For c1 = 0 To 2

       grid1(r1, c1) = InputBox("Enter")

            Next    Next

                For r1 = 0 To 2

            For c1 = 0 To 2

        grid2(r1, c1) = InputBox("Enter")

            Next

        Next

        For r1 = 0 To 2

            For c1 = 0 To 2

grid3(r1, c1) = grid1(r1, c1)+grid2(r1, c1)

            Nex   Next

        Dim temp As String = ""

        For r1 = 0 To 2

            For c1 = 0 To 2

temp = temp & "   " & grid3(r1, c1).ToString()

            Next

            ListBox1.Items.Add(temp)

            temp = ""

        Next

 


2 2 2

3 3 3

1 1 1

 

1 1 1

3 3 3

2 2 2

 

3 3 3

6 6 6

3 3 3

 

    End Sub



 Multi-Dimensional Array: VB.Net मे कई dimensions के array create किए जा सकते हैं। ऐसे array जिसमे एक से जायदा bracket(,,) होती हैं उन्हे multi-dimensional array कहते हैं। Multi-Dimensional array को declare करने के लिए भी Dim, private या public statement का use किया जाता है। इसे declare करते समय इसमे एक से ज्यादा subscripts दी जाती हैं। यह subscripts के multiple के बराबर values store कर सकते हैं जैसे n(2,3) array मे 6 values store की जा सकती हैं।

Syntax:Dim <array name> (script1, script2 …) As <Datatype 

Dim Array_name(2,3,5) as data_type

Jagged Array

किसी अरे के अरे को jagged      अरे कहते है वीबी।नेट मे jagged अरे एक ईएसए अरे होता है जिसमे भिन्न भिन्न dimension तथा साइज़ के एलिमेंट्स होते है इसे array   of array के नाम से भी जाना जाता है| jagged अरे अपने मे कोई वैल्यू के स्थान पर अरे को भी स्टोर कर सकता है  वीबी मे jagged अरे को दो brackets के साथ (साइज़)( dimention) initialize      किया जाता है जिसमे पहला कोष्ठक साइज़ ऑफ अरे को दर्शाता है तथा दूसरा अरे की dimention      को दर्शाता है

      Declaration of  Jagged Array        

नीचे दिये गए syntax मे हम one dim तथा multidimension jaggedअरे को declare करेंगे

      ' Jagged Array with Single Dimensional Array

Dim array_name as data_type()()=new data_type(size)(dimension) {}

Dim jarray As Integer()() = New Integer(1)() {  }

' Jagged Array with Two Dimensional Array

 

Dim Array_name as data_type()(,)=new data_type(size)(,) { }

Dim jarray1 As Integer()(,) = New Integer(2)(,) {  }

उपरोक्त syntax मे jarray  मे हम 2 element को स्टोर कर सकते है तथा दूसरे मे maximum 3 elemrnts को स्टोर कर सकते है

 The following code shows declaring a jagged array named scores of Integers −

Dim scores As Integer()() = New Integer(5)(){}

Dim a As Integer()() = New Integer(4)() {}

        a(0) = New Integer() {0, 0}

        a(1) = New Integer() {1, 2}

        a(2) = New Integer() {2, 4}

        a(3) = New Integer() {3, 6}

        a(4) = New Integer() {4, 8}

        Dim i, j As Integer

        Dim t As String = ""

        ' output each array element's value

        For i = 0 To 4

            For j = 0 To 1

       t = t & "   " & a(i)(j).ToString()

                ListBox1.Items.Add(a(i)(j))

            Next j

            ListBox2.Items.Add(t)

            t = ""

         Next i

    Initialization Jagged Array

In visual basic, we can initialize the arrays upon declaration. The following are the different ways of declaring and initializing the jagged arrays in a visual basic programming language.

 

' Jagged Array with Single Dimensional Array

Dim jarray As Integer()() = New Integer(4)() {}

jarray(0) = New Integer(4) {1, 2, 3, 4, 5}

jarray(1) = New Integer(2) {10, 20, 30}

jarray(2) = New Integer() {12, 50, 60, 70, 32}

' Jagged Array with Two Dimensional Array

Dim jarray1 As Integer()(,) = New Integer(2)(,) {}

jarray1(0) = New Integer(1, 1) {{15, 24}, {43, 54}}

jarray1(1) = New Integer(,) {{11, 12}, {13, 14}, {25, 26}}

' String Array-स्ट्रिंग अरे का उपयोग एक से अधिक स्ट्रिंग वैल्यू को स्टोर करने के लिए किया जाता है

Private Sub Button1_Click()

        Dim names(1, 1) As String

        Dim row, col As Integer

        For row = 0 To 1

            For col = 0 To 1

 names(row, col) = InputBox("Enter string")

            Next   Next

                For row = 0 To 1

            For col = 0 To 1

  Label1.Text = Label1.Text & names(row, col)

Label1.Text = Label1.Text & ControlChars.NewLine

            Next

        Next

 

    End Sub


 

 

 

 

 


1 comment: