Question is apparently to simple to find an answer to (Proper Array Syntax)

I just need to know the proper array syntax. Make me an array, call it myArray and I'll know the rest. I can make an array in other languages, but when I SEARCH for array at msdn I can't find proper syntax for Visual Basic. SO.. please, just write a small array with a few elements... 3 or 4. Thanks.
LVL 1
lionheart620Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
JacamarConnect With a Mentor Commented:
dim myarray() as single
dim inI as integer
dim inJ as integer

inI = 5

Redim myarray(1 to inI) as single

For inJ = 1 to 5
  myarray(inJ) = inJ
Next inJ



This will give you an array with 5 elements that will be
1
2
3
4
5

is this what you were after?
0
 
bobbit31Commented:
Dim myArray(10) as String



0
 
bobbit31Commented:
Or

Dim myArray() as Object

ReDim myArray(10)

btw:

you can also do something like
Dim myArray(1 to 10) as String

for multidimensional
Dim myArray(5, 10) as String



0
 
Hornet241Commented:
One last thing That may come in handy

        Dim myArray() as integer

        For a = 0 to 10
            Redim Preserve myArray(a)
            myArray(a) = a
        Next a

This will increase the size of the Array while preserving the previous values

one thing, it will only work on the outer most dimension
        For a = 0 to 10
            Redim Preserve myArray(2,a)
            myArray(0,a) = a
            myArray(1,a) = a + 1
            myArray(2,a) = a + 2
        Next a

0
 
leojlCommented:
hi lion,
Here is an example of a 2 diminsional array

Private Sub Form_DblClick()
Dim MyArray(1 To 3, 1 To 4) As Integer ' default is Variant
'to populate
For i = 1 To 3
For j = 1 To 4
MyArray(i, j) = i * j
Next
Next
'to see the result
For n = 1 To 3
Print MyArray(n, 1), MyArray(n, 2), MyArray(n, 3), MyArray(n, 4)
Next
End Sub

sincerely   leo
0
All Courses

From novice to tech pro — start learning today.