Simple text import

My red comments indicated that however

Code:
Open pathtofile For Input As #fileNum[COLOR="Green"] ' Open the text file for reading[/COLOR]

Do Until EOF(fileNum)[COLOR="green"] ' read the whole file line by line[/COLOR]
    Line Input #fileNum, strPGNdata [COLOR="green"]' pass the current row of text to the string[/COLOR]    
[COLOR="green"]'Process the line of text here[/COLOR]
Loop [COLOR="green"]' Move to next line in text file[/COLOR]

Close #fileNum[COLOR="green"] ' End of text file close it[/COLOR]
 
I think that is going to be complicated because I have already written all the code for parsing. It would involve too many changes.

I just need a separate routine to import a text file into a string.
 
Lets say you have all you parsing code in a function Called ParseText

Code:
10 Do Until EOF(fileNum) ' read the whole file line by line
20    Line Input #fileNum, strPGNdata ' pass the current row of text to the string    
'Process the line of text here
30 Call ParseText(strPRNdata)
40 Loop ' Move to next line in text file

At line 30 you simply pass the current line of text to your function that evaluates the current line of text

Then every loop it simply processes eachline of text in the file until it reachs the end. Should be no need to revise your code.
 
Its not a linear parsing of each text line though. For example, it does a different looping if it finds a line without a certain criteria met. Then, it goes through several more lines inside that loop until another criteria is met. Then it goes back to the normal loop.

Consequently, I can't do the loop reading line by line as suggested, as it has a kind of lookahead.
 
Perhaps I could just add vbcrlf to the end of each line as it is input?
 
What you may need to do in that case is the following
Dim StrFileconents As String

Code:
10 Do Until EOF(fileNum) ' read the whole file line by line
20    Line Input #fileNum, strPGNdata ' pass the current row of text to the string    
StrFileContents = StrFileContents & StrPGNData & vbCrLf


30 strPRNdata = ""

40 Loop ' Move to next line in text file

Essenstially what this is doing is copying the whole file into one long string with a carriage return at the end of each line. You will then be able to to use your
var = Split(StrLineContents, vbCrLf)

To create an array. Never done it this way before so there maty be some issues here. Beats me why you did all the parsing code prior to being able to read the file in the first place.
 
Beats me why you did all the parsing code prior to being able to read the file in the first place.
I had reiterated the same thing at least twice in the OP's other post regarding his parsing code. Read the line, parse, read line, parse. That should be the sequence of events. Reading into a string before parsing is pointless and double work.
 

Users who are viewing this thread

Back
Top Bottom