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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read from a text file

Status
Not open for further replies.

75cl

Programmer
Joined
Nov 1, 2001
Messages
43
Location
US
How do you read a text file in VB 6.0?
 
It depends on how you want to import the data. Is the contents delimeted or do you want to read entire lines?
Code:
Dim Val1,Val2,Val3
Open ("C:\test.txt") For Input As #1
    Input#1,Val1,Val2,Val3
Close #1

Dim sLine As String
Open ("C:\test.txt") For Input As #1
    Line Input#1,sLine
Close #1
 
Or do you want to read the entire file?
[tt]
Open ("C:\test.txt") For Binary As #1
AllLines$ = String$(Lof(1), 32)
Get #1, 1, AllLines$
Close #1
Text1.Text = AllLines$
[/tt]

I guess there are several ways to do this.

VCA.gif
 
Hi,

OR

Filefree = freefile

Open "C:\thefile.txt" for input as #Filefree

While Not (EOF(filefree))
Input #filefree, ReadString
'(1) List1.AddItem (ReadString)
'(2) Text1.Text=Text1.Text+ReadString+Chr$(10)+chr$(13)
Wend

Close #filefree


In the above remove the REM Mark ' and the number and parenthesis marks for th choice you require.

(1) Puts the lines of text into a listbox called LIST1
(2) Puts the lines of text into a text box called TEXT1.

In the latter make sure Multiline property for the textbox is TRUE

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top