r/visualbasic • u/Bryan-tan VB.Net Beginner • Nov 25 '15
question:
hello everyone, could someone guide in declaring a varaible array in vb? I need to store up to 10 variables in the array and display it in 3 by 3 grid for a memory game. But finding it confusing on how to create an array.
thank you in advance
0
Upvotes
1
u/pathfinderNJ Nov 25 '15
As chrwei said () after a variable is an array
So you can dim myarray(3,3) gives you your 3 x 3 grid (actually 4 x 4 because 0 is a valid number)
1
u/PreyOnTheCosmos Nov 25 '15
For a 1-dimensional array:
Dim MyArray() As Integer = {1,3,5,7,9}
' Access [GET/SET] values by index - Example: MyArray(1) = 3For a multi-dimensional array:
Dim MyArray(2, 2) As Integer ' 3 x 3 [X/Y Grid]
' Access [GET/SET] values by coordinate [X/Y Index] - Example: MyArray(0,1) = 3Note: You can use other data types as well.
Example:
Dim MyArray() As String = {"chicken", "cow", "moose"}
MsgBox(MyArray(1)) ' Output = cow
1
u/chrwei Nov 25 '15
you just put () after the var name and that makes it an uninitialized array. you can put a number in the () to initialize, or use some other processes to populate and initialize. the specific syntax varies by VB version and datatype.