Reading Text Files (1 Viewer)

Thales750

Formerly Jsanders
Local time
Today, 00:35
Joined
Dec 20, 2007
Messages
1,702
Hey Guys,

Can anyone tell me what is the purpose of the second variable, please?


Code:
Dim MyStr1 as string
dim MyStr2 as string

Open "TESTFILE" For Input As #1
Do While Not EOF(1)    ' Loop until end of file.
    Input #1, MyStr1, MyStr2
    me.txtStr1 = MyStr1
    me.txtStr2 = MyStr2
Loop
Close #1    ' Close file.
It works fine just using the first variable.

Thanks,
 

Micron

AWF VIP
Local time
Today, 00:35
Joined
Oct 20, 2018
Messages
3,409
IIRC, the second variable isn't required but would be for the second value in pairs of values. So if you had data pairs like "text", number , the first variable would be typed as a string, the second as a number data type. With 1 variable, I guess only the first value of a value pair would be assigned in each loop iteration. Not 100% sure about that. Whether or not you should have 2 (or any particular count of variables) would depend on what your file looks like.
 

vba_php

Forum Troll
Local time
Yesterday, 23:35
Joined
Oct 6, 2019
Messages
2,884
to expand on what guy said, you should look here:


but that doesn't do a really great job as the code is .NET oriented anyway. in terms of what all is available within the function itself, you can do all of the following with INPUT:

Code:
readline
read any number of characters
read the entire file
furthermore, another option to use if you want to stream data via I/O is code like this:
Code:
CreateObject("Scripting.FileSystemObject")
 

strive4peace

AWF VIP
Local time
Yesterday, 23:35
Joined
Apr 3, 2020
Messages
542
hi Thales,

normally, using this method, as you loop through the file, you'd create records too. This code doesn't make much sense because each line would just overwrite what is already in the textbox controls
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom