-
I have a text file like this
1020534847101000,mark,blue
1030534877204000,karen,red
1040534678405000,paul,green
I want to loop through the file and only store the first
part/number in the variable store. Then show in msgbox.
so on the first loop store would hold 1020534847101000
next loop would have 103... etc
but what is happening is I get the number then I get the name
then the color,
How do I only get the first part, know what I mean ?
Dim store as string
filenum = freefile
Open filename For Input As #filenum
Do Until EOF(filenum)
Input #filenum, store
MsgBox store
Loop
Close #filenum
Thanks
> locutus
-
Try this: (In Bold are things I've added)
Dim store as string
Dim iPos As Integer
filenum = freefile
Open filename For Input As #filenum
Do Until EOF(filenum)
Input #filenum, store
iPos = InStr(store, ",")
If iPos > 0 Then store = Left(store, iPos - 1)
MsgBox store
Loop
Close #filenum
------------------
Yonatan
Teenage Programmer
E-Mail: [email protected]
ICQ: 19552879
-
Thanks for your reply
but unfortunatly it didn't work. I know the easy way to do it is to declare a record or load of variables and load the textfile line that way but I was looking for a shortcut!
Anyone ?
>locutus
-
Test it:
-----------------
Dim MyNumber$, MyString0$, MyString1$
On Error Resume Next
Open "d:\file.txt" For Input As #1
Do While Not EOF(1)
Input #1, MyNumber, MyString0, MyString1
Debug.Print MyNumber
Debug.Print MyString0
Debug.Print MyString1
Loop
Close #1
------------------
smalig
[email protected]
smalig.tripod.com
-
As there are commas in each record, each Input instruction alone will get only one variable en each line. There are two workarounds:
1- Use Line Input instead to get the whole line and then separate the variables with InStr as Yonatan suggested:
Line Input #1, store
2- Use "dumb" Inputs:
While Not Eof(1)
Input #1 MyNumber
MsgBox MyNumber
Input #1 a$
Input #1 a$
Wend
The last will only work if there are always one number and two strings in each line, ya know?
Regards.
[This message has been edited by Juan Carlos Rey (edited 11-04-1999).]