|
-
August 2nd, 2001, 08:35 AM
#1
reading form text file
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
-
August 2nd, 2001, 08:48 AM
#2
Re: reading form text file
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!
-
August 2nd, 2001, 08:50 AM
#3
Re: reading form text file
Thank you very much.
Regards
Valery Iskarov Nikolov
http://listen.to/quark
-
August 2nd, 2001, 08:53 AM
#4
Re: reading form text file
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
-
August 2nd, 2001, 08:55 AM
#5
Re: reading form text file
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
-
August 2nd, 2001, 08:55 AM
#6
Re: reading form text file
line input #1, oneLine
where oneLine is a string variable.
-
August 2nd, 2001, 09:17 AM
#7
Re: reading form text file
Were you using "Input" or "Line Input" to read the lines before? Line Input reads through to the line feed.
-
August 2nd, 2001, 09:27 AM
#8
Re: reading form text file
Thanks, Line Input # Statement did the job perfectly.
Regards
Valery Iskarov Nikolov
http://listen.to/quark
-
August 2nd, 2001, 09:28 AM
#9
Re: reading form text file
thanks,
I did'n notice the difference between "line input" and "input" statements
regards,
Valery Iskarov Nikolov
http://listen.to/quark
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|