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

Thread: Arrays in VB

  1. #1
    Join Date
    Jul 2000
    Posts
    67

    Arrays in VB

    Hello!

    People have told me that the best way to do a controlled print of a recordset is to put the recordset data into a array, then read the array values into variables, and print selected information line by line in a txt file.
    My problem is that i do not know how to get the data from the recordset into the 2D. array, and I do not know how to get array information into variable that i can do a print of... Do you have an example (with some code) of how this can be done?


    Here is some of my code:

    Dim rsNames As ADODB.Recordset
    Dim sData As String
    sData = ""
    For Each fld In rsAddresses.Fields
    sData = sData & fld.Name & ", "
    Next

    Do Until rsAddresses.EOF
    sData = ""
    For Each fld In rsAddresses.Fields
    sData = sData & fld.Value & ", "
    Next
    rsAddresses.MoveNext
    Print #1, sData; 'prints address
    Loop


    What i want is to get sData into an array, and then do a print from the array or something....

    I'm thankful for all suggestions and tips.


  2. #2
    Join Date
    Jun 2001
    Location
    Sri Lanka
    Posts
    272

    Re: Arrays in VB

    If u want both field values to be in the same 2D array;
    Dim rsNames as ADODB.Recordset
    Dim sData as string
    Dim i as integer
    Dim dataArray() as string

    Redim dataArray(1,0) as string
    sData = ""

    for Each fld In rsAddresses.Fields
    sData = sData & fld.Name & ", "
    dataArray(0,i) = fld.Name
    dataArray(1,i) = fld.Value
    Redim Preserve dataArray(1,i+1) as string
    i = i + 1
    ' I'm not familiar with print# ...
    ' but I think it can be used as follows
    print #1, dataArray(0,i) ; 'prints address
    print #1, dataArray(1,i) ;
    next




    If u don't know how to Rate an answer, then Rate my answer to learn, If u know, then practice it

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