Click to See Complete Forum and Search --> : 2 D array
Balcaf
April 20th, 2001, 03:48 AM
I need to write code that will load the contents of 2 fields from a database into a 2 d array.I already have the recordset open. I can't figure out how to take the two strings variables pstrLastName and pstrFirstName and dump them into an array.HELP!!!
Franco
John G Duffy
April 20th, 2001, 07:25 AM
private Sub Form_Load()
Dim myArray(1, 10) ' Thats two columns, 10 rows
Dim pstrFirstName
Dim pstrLastName
pstrFirstName = "Pete"
pstrLastName = "Jones"
myArray(0, 3) = pstrFirstName ' Add first name to column 1, element 3
myArray(1, 3) = pstrLastName ' Add last anme to column 2 element 3
MsgBox myArray(0, 3) & " " & myArray(1, 3)
End Sub
John G
Iouri
April 20th, 2001, 08:01 AM
Hi John
Isn't it supposed to be
Dim myArray(2, 10) ' Thats two columns, 10 rows
Iouri Boutchkine
iouri@hotsheet.com
John G Duffy
April 20th, 2001, 12:53 PM
Iouri, actually the statement which reads
Dim myArray(1, 10) ' Thats two columns, 10 rows
is in error. It should read:
Dim myArray(1, 9) ' Thats two columns, 10 rows
The subscript, when dimensioning an array in VB is the upper bound with the lower bound always being 0.
Hence Dim MyArray(5) actually sets up 6 elements (0-5). This is unlike other languages where the subscript actually defines the number of elements.
VB.Net is addressing this issue and its initial design changes it to conform to the other language specs but there has been such a howl from the VB community, that Microsoft is going to leave it alone. Imagine having to go through all your programs that use arrays and having to change youe DIM and Redim statements to conform to the new standard as well as having to weed through the code to ensure that change did not effect your logic.
John G
forty7
April 20th, 2001, 12:59 PM
thanx for this info. no offense, but i double checked msdn to verify. i'm stunned that this is true, and i feel like a bonehead that every array i've created in vb has a trailing empty element.
at least if they chose to change it in vb.net my code would already conform to the new standard.
i gave ya a 10!
thanx/good luck,
adam
John G Duffy
April 20th, 2001, 01:19 PM
Minor differences like this between languages can indeed create some massive headaches.
John G
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.