locked
How to use 2D Array ? RRS feed

  • Question

  • Hi, every one..

    I need One help form you. i want   to know how to use 2D array in VB coding. whose lenght is unknown that means it 's vary from application to another.for one cretaria it si 20 for some other scenario it is 15. so how to declare and initialze the 2D array for the same case.

    Thanks

    Monday, September 4, 2006 7:05 AM

Answers

  • One of the nice new features of .NET is the list(Of T)...It has all of the benefits of an array and more...for one you don't have to worry about bounds or the index ....

    Dim MyList As New List(Of Integer)

    Dim Index As Integer = 0

    Dim x As Integer = 0

    For Index = 0 To 10

    MyList.Add(x)

    x = +2

    Next

    For Index = 0 To 10

    Debug.Print(CStr(MyList(Index)))

    Next

     If you actually need to multiple dimensions of random integers you can also utilize a custom collection ...or do as stated and dimension your array with variables that can be set at runtime or set with maximum values

    Monday, September 4, 2006 11:54 PM
    Moderator

All replies

  • Dim yourArray(x, y) As Integer

     

    Monday, September 4, 2006 8:02 AM
  • i don't know size of the array. it depends on some other data.Tell me whearher  variable holds array size .Then pass that variable into array for defining the lenght of the array is it possible?

    Thanks in advance.

     

    Monday, September 4, 2006 10:06 AM
  • x and y in my example above can be variables with values only known at runtime.

     

    Monday, September 4, 2006 2:57 PM
  • One of the nice new features of .NET is the list(Of T)...It has all of the benefits of an array and more...for one you don't have to worry about bounds or the index ....

    Dim MyList As New List(Of Integer)

    Dim Index As Integer = 0

    Dim x As Integer = 0

    For Index = 0 To 10

    MyList.Add(x)

    x = +2

    Next

    For Index = 0 To 10

    Debug.Print(CStr(MyList(Index)))

    Next

     If you actually need to multiple dimensions of random integers you can also utilize a custom collection ...or do as stated and dimension your array with variables that can be set at runtime or set with maximum values

    Monday, September 4, 2006 11:54 PM
    Moderator