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

no carraige return in file (?) 3

Status
Not open for further replies.

daveleo

Programmer
Mar 2, 2002
54
0
0
US
hi
i am trying to read a sequential text file line by line using the command

Line Input #1, scratch

so the entire line will be read into the string "scratch".

i have done this many times before and it works fine, however i have a file that i am reading and this command appears to be loading the entire text file into the variable "scratch"...i ran several cases to show this is what is happening.

the text file was generated by a program in UNIX and it opens and appears fine in WORDPAD on a PC.....but i believe the problem may be that there are no carraige returns or line feeds at the end of each line even thought the file looks fine in WORDPAD.

how can i read each line of this file in a VB6 program?

thanks for your time.

daveleo
 
Unix files are generally delimited with LF characters (ASCII character 10). You can read the whole file, then split on Chr(10).

Use Split function to get it all into an array:

[tt]
arySplit = Split(scratch, vbLF)
[/tt]

You can then loop through the array using Lbound and Ubound for your loop limits.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Or you can use the Microsoft Scripting Runtime library.

VB's Line Input statement only recognizes the end of line with vbCrLf. On the other hand the ReadLine method of the TextStream object in Scripting library takes care of that limitation. In addition to vbCrLf, it recognizes the end of line with vbLf as well allowing you to read unix text files line-by-line correctly. See this example code.
___
[tt]
Private Sub Form_Load()
Dim File As String
File = "C:\SCANDISK.LOG" '
With CreateObject("Scripting.FileSystemObject")
With .OpenTextFile(File, 1) '1=for reading
Do Until .AtEndOfStream
Debug.Print .ReadLine 'read line-by-line
Loop
End With
End With
End
End Sub[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top