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

Reading lines from a text file problem 2

Status
Not open for further replies.

Sech

Programmer
Jul 5, 2002
137
GB
I'm currently creating a database that needs to read through the lines of a text file one at a time and alter certain characters. I do not have a problem with the altering of the characters, however there is a problem with grabbing the entire lines from the file. Below is some example code which I hope you can understand:

Code:
Dim intTextFile As Integer
Dim strPath As String
Dim strFileName As String
Dim strInputLine As String

strPath = "C:\"
strFileName = "test"

'Open the text file
intTextFile = FreeFile
Open strPath & strFileName & ".txt" For Input As #intTextFile

'Go through the input file line by line...
Do While Not EOF(intTextFile)
    
     'Open current line
     Input #intTextFile, strInputLine

In the above example, the text file contains many records which have fields that are not comma seperated. In other words I am setting up the field splits using import specs. After opening each line I make the relevant changes and then add it to a different output file. The problem is that most of the lines are opened correctly, however if there is a comma in any of the fields of the line, it counts this as a line break and splits the line into sections. The below example line is made up from 4 fields - ID, Name, Description and Ref No:

1BobManager approved changes, contact customer375349

When the code gets to this line it would first take "1BobManager approved changes" and then the next time around it would take "contact customer375349". What I want is for the whole line to be taken. Does anyone know why this is happening and how to get around it? Most of the lines do not contain any commas and so are detected correctly.

Please help!
 
go to my website & get the importtextfiles.zip file.
The database in there has a class module which you could use to read a line at a time from a text file. It also has options to miss blank lines, only take alphanumeric characters etc. There is an example for its use in the file.

HTH

Ben ----------------------------------------
Ben O'Hara
Home: bpo@SickOfSpam.RobotParade.co.uk
Work: bo104@SickOfSpam.westyorkshire.pnn.police.uk
(in case you've not worked it out get rid of Sick Of Spam to mail me!)
Web: ----------------------------------------
 
Input # reads lists of variables.

Try using "Line Input #" as this will read an entire line of text. Look under "Line Input # Statement" in the online help for more information.

Hope this helps

Daren


Must think of a witty signature
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top