CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: 2 D array

  1. #1
    Join Date
    Apr 2001
    Location
    New England
    Posts
    2

    2 D array

    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


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: 2 D array


    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

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: 2 D array

    Hi John

    Isn't it supposed to be
    Dim myArray(2, 10) ' Thats two columns, 10 rows

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: 2 D array

    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

  5. #5
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: 2 D array

    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
    thanx/good luck

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: 2 D array

    Minor differences like this between languages can indeed create some massive headaches.

    John G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured