05-07-2003, 01:09 AM
I need to load text file into a string,
I know that I shuld open a file:
Open "FILE.txt" For Append As #txtFile
Now, how can I load the txt?
05-07-2003, 01:16 AM
Dim sString As String, sInput As String
Open "C:\File.txt" For INPUT As #txtFile
While Not EOF(txtFile)
Input #txtFile, sInput
sString = sString & sInput
sInput = ""
05-07-2003, 01:29 AM
I get error message "Bad file name or number"
And the file exist...
Working Great, Thanks mate! :D
05-07-2003, 01:34 AM
You have to first assign the variable txtFile a number - the best way is using the freefile function, which will return the next available file number.
However, txtFile is a bad name for this variable, as it implies that the variable is a text box, and not an integer. A more appropriate name would be intFile.
Also: Use the Line Input command, rather than the Input command. This will return the entire line, rather than splitting the line into multiple chunks if there's a comma present on the line.
Really, a much faster method would be to input the entire file into the string variable in a single call.
Dim strFile As String
Dim intFile as Integer
intFile = FreeFile
Open "C:\File.txt" For Input As #intFile
strFile = Input$ (LOF(intFile),#intFile) ' LOF returns Length of File