Click to See Complete Forum and Search --> : Retrieving from text file


January 7th, 2000, 01:54 PM
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.

Aaron Young
January 7th, 2000, 02:21 PM
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
ajyoung@pressenter.com
aarony@redwingsoftware.com