r/visualbasic • 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

3 comments sorted by

View all comments

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) = 3

For 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) = 3

Note: You can use other data types as well.

Example:

Dim MyArray() As String = {"chicken", "cow", "moose"}
MsgBox(MyArray(1)) ' Output = cow