Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a text File

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
HI!!
I have a text files with data in the form
11234
109878
0.23444
.
.
.
.

I need to read each item and use it as a variable in my program.
say a= 11234
b=109878
c=0.23444
.
.

I would greatly appreciate your help.

Thanks
 
One way is:

Open &quot;c:\<file>&quot; For Input As #1
Input #1, a
Input #1, b
Input #1, c
Close #1

But there are many file modes in VB. Try a search on google to learn more about the file modes.

Buffer0verflow
 
Using the filesystemobject which you need to include Microsoft scripting runtime in your project references before you can use and arrays to store the data use the following code.

Dim fso, f
Dim a() As String

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f = fso_OpenTextFile(App.Path() & &quot;\JobEuro.Log&quot;, ForReading, TristateFalse)
Counter = 1
Do While f.AtEndOfStream <> True
ReDim Preserve a(Counter)
a(Counter) = f.ReadLine
Counter = Counter + 1
Loop
f.Close



This will store whatever comes out of the file as a string if you want to make them integers then change the declaration to Dim a() as Integer and when reading use
a((counter) = CInt(f.readline). Hope this is some help to you.
Mark

The key to immortality is to make a big impression in this life!!
 
Bufferoverflow and Spellman,
That was really prompt reply and I could sove the problem which I have struggling for the past threew eeks.

Thanks a LOT

Code_novice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top