
reading strings from a text file
It's not as difficult as you think. I did something similar recently.
-------------------------------------------------------------------
Dim CurrentLine, Variable1, Variable2 as String
Dim WorkingOn, PrevWorkingOn as byte
PrevWorkingOn = 0
Open "InputFile.txt" for input as #1
While Not EOF(1)
WorkingOn = 0
Line Input #1, CurrentLine
If Left(CurrentLine,10) = "Variable1:" then WorkingOn = 1
If Left(CurrentLine,10) = "Variable2:" then WorkingOn = 2
If WorkingOn = 0 then 'Continued variable
Select Case PrevWorkingOn
Case 0: <Skip This Line or Handle Error - this will only occur
if the first line in the text file does not have
a variable: prefix.>
Case 1: Variable1 = Variable1 & CurrentLine
Case 2: Variable2 = Variable2 & CurrentLine
End Select
Else ' New Variable
Select Case WorkingOn
Case 1: If Variable1 <> "" Then <Process or Output Variables>
Variable1 = Mid(CurrentLine,11)
Case 2: Variable2 = Mid(CurrentLine,11)
End Select
End If
PrevWorkingOn = WorkingOn
Wend
-------------------------------------------------------------------
This is a simple example, with only 2 variables. Obviously you will
want to change it to accomodate more. If you have too many more
variables, you may want to use Variable(n) rather than Variable1,
Variable2, etc...
Hope this helps.
-Doug.
Quote:
> I posted a note a while ago asking for some help with reading a txt file,
> capturing variables and then writting them to a database table.
> The suggestion was to use a while not at EOF routine that used lineinput to
> grab the variables. I had no problems with the post processing, and thus it
> worked well. (Thanks to all those that helped out). This was for variables
> that were within the same line.
> The problem is now that I need to read in some variables that are long text
> strings that may go over a number of lines. eg
> Variable1:blah blah blah blah
> blah blah blah blah
> Variable2:more blah blah
> I need to be able to read the ":" at the end of the 2nd variable name and
> thus have the first variable captured. I know the order that the variable
> names will appear, and that they will always have a ":" to end the variable
> name, but not the number of lines that they will take up.
> Any hints would be great.
> Thanks
> --
> Michael Whitaker
> WAIS