Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays in vb? 1

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
Can you make two dimensional arrays in vb?

i want to make an array with 2 rows and 5 cols

how would i do that?

thanks
 
Thanks Jeff

now lets say I had an array of Test(2, 2)

meaning it has 2 rows and 2 cols
And I set
test(0, 0) = "X"
test(0, 1) = "X"
test(1, 0) = "X"
test(1, 1) = "X"

How would I print this on the form using a for loop so it comes out like this
XX
XX
 
Try something like this:
Code:
Dim sVal As String

For i = 0 To 1
    For j = 0 To 1
        sVal = sVal & test(i, j)
    Next j
    sVal = sVal & vbCrLf
Next i

MsgBox sVal
Or, if there are always 2 columns:
Code:
Dim sVal As String

For i = 0 To 1
    sVal = sVal & test(i, 0) & test(i, 1) & vbCrLf
Next i

MsgBox sVal
 
By the way Savok an array declared as: Dim Test(2,2) As String will actually have Three Rows and Three Columns and the index of either dimension can run from 0 to 2.

And now somebody will reply: true, unless you specify Option Base 1 at the beginning of your module, in which case the index will run from 1 to 2. Well, most of the time, because the said Option Base 1 will NOT stop some functions returning arrays that are Zero-based: most noticeably the Split Function. _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
rvBasic,

... but you could also use

The subscripts argument uses the following syntax:
[lower To] upper [, [lower To] upper] . . .

... then all of the preceeding are sbject to interpertation. but then your original statement is 'good enough' for thislevel of inquiry/response.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
I would agree with everything that rvBasic and MichaelRed posted. Just my 2 cents so to speak . . . - Jeff Marler B-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top