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

    Retrieving from text file

    set db = opendatabase("c:\directoryname",flase,false,"text")
    set rs = db.openrecordset("filename",dbopendynaset)
    do until rs.eof
    msgbox rs(0)&rs(1)
    rs.movenext
    loop

    it prints for rs(0) but gives error for rs(1)
    the data i have in my file is in this order

    ABC
    XYZ

    it prints only XYZ if i just ask it to print rs(0) and NOT ABC why?
    What should i do such that both are printed.


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Retrieving from text file

    You're making a couple of mistakes here..
    You stated your file is in the Format:
    In reply to:


    ABC
    XYZ




    Therefore, there is only 1 Field, hence rs(1) gives an error as it referes to Field 2

    Secondly, the First "Record" is treated as the Column/Field Headers, which is why you don't get to see ABC, you'll find it if you look under rs(0).Name Which is the Field Header.

    Try this:

    private Sub Command1_Click()
    Dim oDB as Database
    Dim oRS as Recordset

    set oDB = OpenDatabase("C:\", false, false, "Text")
    set oRS = oDB.OpenRecordset("File.txt", dbOpenDynaset)
    Caption = oRS(0).Name
    While Not oRS.EOF
    List1.AddItem oRS(0)
    oRS.MoveNext
    Wend
    oRS.Close
    oDB.Close
    End Sub




    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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