Results 1 to 4 of 4

Thread: datagrid values into an array

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Posts
    22

    datagrid values into an array

    how wood i get the results of my qeury into an array.
    Example.. my query returned the field "order". thgere are 130 records that werer returned in that field. i want those values to be put into an array.
    Oder
    1
    2
    3
    4
    5
    etc.... array wood contain 1,2,3,4,5 etc..
    thax
    trin

  2. #2
    DerFarm
    Guest
    easiest way would be to ReDim an array of the appropriate type to the number of records.

    Assume rs is the recordset:

    Code:
        Dim NumAry()
        ...
        ...
        redim NumAry(rs.recordcount)
        while not rs.eof
            NumAry(rs.absoluteposition)=rs.fields("fieldname").value
            rs.movenext
        wend
    
    
    ...
    ReDim will set the lowerlimit to 0 and the upper limit to the
    number of records in the dataset. You, however, DO NOT have to
    use the zeroth element.

    HTH

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Posts
    22
    that worked great thanx, but i have one question..its silly question but here goes..this is my code..
    Code:
    Private Sub cmdArray_Click()
    Dim elements As Integer
    Dim Numarray() As String
    
    elements = Adodc1.Recordset.RecordCount
    ReDim Numarray(elements)
    While Not Adodc1.Recordset.EOF
        Numarray(Adodc1.Recordset.AbsolutePosition) = Adodc1.Recordset.Fields("Exam_order").Value
        Adodc1.Recordset.MoveNext
        Wend
    lblArray = Numarray(1)
    how do u declare "rs" in your example. I dont want to have to tpye out adodc1.recordset.blah blah. everytime in my code.I want to use rs. eof for example like you have in your example.
    thanx
    trin

  4. #4
    Alain
    Guest

    Here it goes...

    Here is an example of what I do:

    VB Code:
    1. Dim rc as recordset
    2.  
    3.      Set rc = adodc1.recordset
    4.  
    5.      'then...
    6.      a = rc.fields("yourfield")
    7.      b = rc.recordcount
    8.      'etc....

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