|
-
Jun 9th, 2001, 07:44 PM
#1
Thread Starter
Junior Member
Some more reading from a file help please
Grr.. this is really starting to annoy me. I'm trying to read the first thing from each line, but the code I've got is now only reading the first thing on the last line.
Code:
Private Sub Form_Load()
Dim name As String
Dim i As Integer
'to make sure that it starts at i=0
i = -1
Open filename For Input As #1
While Not EOF(1)
Input #1, name
i = i + 1
Wend
Close #1
lblName(i).Caption = name
Any ideas? Please?
Thanks.
-
Jun 9th, 2001, 07:48 PM
#2
Well, you actually are reading the first thing from each line, but you are not doing anything with any of the data you pull in, except for the last line try this :
VB Code:
Private Sub Form_Load()
Dim name As String
Dim i As Integer
'to make sure that it starts at i=0
i = -1
Open filename For Input As #1
While Not EOF(1)
Input #1, name
lblName(i).Caption = name
i = i + 1
Wend
Close #1
End Sub
see if that works...
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 9th, 2001, 07:52 PM
#3
Thread Starter
Junior Member
Thanks for that, but there's still a problem. Instead of reading one thing from each line, its reading the first, second, third, fourth thing etc. on each line before going to the next line. Is there a way to JUST read the last line?
And yes, I *did* put commas between all the entries in the text file
-
Jun 9th, 2001, 07:57 PM
#4
try using Line Input, and trim off what you don't need :
VB Code:
Private Sub Form_Load()
Dim name As String
Dim i As Integer
'to make sure that it starts at i=0
i = -1
Open filename For Input As #1
While Not EOF(1)
Line Input #1, name
lblName(i).Caption = Left(name, Instr(1,name",")-1)
i = i + 1
Wend
Close #1
End Sub
see if that works
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 9th, 2001, 08:11 PM
#5
_______
<?>
Code:
Private Sub Command1_Click()
'if it's comma delimited you can do this.
'assuming there are four fields per line.
Dim one, two, three, four
Open "C:\my documents\myfile.txt" For Input As #1
Do While Not EOF(1)
Input #1, one, two, three, four
List1.AddItem one 'list only the 1st variable
Loop
Close
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|