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

Reading a file from VB correctly 1

Status
Not open for further replies.

fugigoose

Programmer
Joined
Jun 20, 2001
Messages
241
Location
US
Why is that VB can only read a file correctly if it's generated by VB? I have a scripting language for my program, and I need users to be able to write their own scripts. For whatever reason, VB refuses to read the first line. I always have this problem, it's so annoying. I'm just using the good old BASIC syntax:

open "myfile.txt" for input as #1

I'd gr8ly apreciate any insight on how to read a file line by line from line 1 to the last line in the file. Thanx.
 
Dim Yourline
Open "TEXTFILE" For Input As #1 ' Open file.
Line Input #1, YourLine ' Read line into your variable.
Close #1 ' Close file.
 
Dim sFullString as string
Dim sTemp as String

Open "textfile.txt" for input as #1
Do Until EOF(1)
Line Input #1, sTemp
sFullString = sFullString & sTemp
Loop
close #1
 
Private Sub Command1_Click()
Dim TextLine(255)
Dim x
Dim y
Let y = 0
Let x = 0
Open "c:\TEST" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine(x) ' Read line into variable.
Let x = x + 1 ' Increment x
Loop

Close #1 ' Close file.
For y = 0 To x Step 1
Debug.Print TextLine(y)
Next y
End Sub


Make sure the lines in the text file are ended with a carriage return .....
 
Private Sub Command1_Click()
Dim intFreeFile As Integer
Dim sText As String
Dim lText As String

intFreeFile = FreeFile
Open "C:\my documents\test.txt" For Input As #intFreeFile
While Not EOF(1)
Input #intFreeFile, lText
Debug.Print lText
sText = sText & lText
Wend
Close #intFreeFile
Debug.Print sText
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top