Click to See Complete Forum and Search --> : reading form text file
vin
August 2nd, 2001, 08:35 AM
Hi,
I need to read a line from text file. I tried to use input statement, however it reads it untill separator. i.e if I have a comma in htis line it reads until it and the next read continues after it. So how can I read the whole line to the end?
Thanks
Valery Iskarov Nikolov
http://listen.to/quark
Ghost308
August 2nd, 2001, 08:48 AM
See if this code helps out.. it is based on the Windows Script Host object FileSystemObject.
Dim fso
Dim myfile
set fso = CreateObject("scripting.filesystemobject") 'create the FileSystemObject
set myfile = fso.opentextfile("c:\test.txt") 'use path to your text file
sLine = Trim(myfile.readline) 'read the first line
MsgBox sLine 'show me the money
To read multiple lines, just put the code with the ReadLine method in a loop and your file should be read sequentially.
I just tested it to make sure that it will read through commas and it worked just fine. Hope that helps!
vin
August 2nd, 2001, 08:50 AM
Thank you very much.
Regards
Valery Iskarov Nikolov
http://listen.to/quark
Ghost308
August 2nd, 2001, 08:53 AM
I haven't tested this code to make sure it runs through commas, but i think it should... this is if you prefer using the...
Open "File" for input as #1
...method of file reading, this code should do the trick.
Open "c:\test.txt" for input as #1 'open it up
Line input #1, txt 'read the first line
MsgBox txt 'show me some more of the money
vin
August 2nd, 2001, 08:55 AM
That was the first I tried but it wouldnt read through commas. Input statement treats commas like separator...
I think file system object will do it.
Valery Iskarov Nikolov
http://listen.to/quark
shree
August 2nd, 2001, 08:55 AM
line input #1, oneLine
where oneLine is a string variable.
Ghost308
August 2nd, 2001, 09:17 AM
Were you using "Input" or "Line Input" to read the lines before? Line Input reads through to the line feed.
vin
August 2nd, 2001, 09:27 AM
Thanks, Line Input # Statement did the job perfectly.
Regards
Valery Iskarov Nikolov
http://listen.to/quark
vin
August 2nd, 2001, 09:28 AM
thanks,
I did'n notice the difference between "line input" and "input" statements
regards,
Valery Iskarov Nikolov
http://listen.to/quark
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.