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

Single Line From A Text File 2

Status
Not open for further replies.

snt

MIS
Jun 19, 2000
104
US
I need to extract a single line of text from a text file and assign it to a variable so I can display it. The problem is that the user will open the file so I can not specify a file name. The line of text is a time stamp that is in the same position in every file that would be opened and starts with time = . Does any one know how I could get the time stamp from the file that the user opens and assign it to a variable?

Much thanks.
 
you have a reference to a multilist, which you use to setup the number of sets for the graph. What is in the multilist?
 
The multilist is the list of open files.
fname
 
ok - in that case, try the following:

i = multilist.listindex
FoundIt = False
TimeStamp(i, 1) = ""
TimeStamp(i, 2) = ""

and so forth
 
TimeStamp(i, 1) = ""

'Subscript Out Of Range'??
 
how many files are in the multilist? you may need to redim the timestamp array to be at least as large as listcount of the multilist.
 
to start there are no files in the multilist. i believe that it is setup for 8 files. anything more then that there was a problem ~ if i remember correctly
 
Then you need to estalish a counter and increment it each time you execute the code which gets the timestamp.

so

dim FileCounter as Integer

at the beginning of the program

FileCounter = 0

then


FoundIt = False
FileCounter = FileCounter + 1
TimeStamp(FileCounter, 1) = ""
TimeStamp(FileCounter, 2) = ""
FileHandle = FreeFile
Open (fdir + fname) For Input As #FileHandle
TimeStamp(FileCounter , 1) = fdir + fname

This might be a good place to
multilist.additem (fdir + fname)
this will keep the multi list in sync with the array

FoundIt = EOF(FileHandle)
While FoundIt = False
Line Input #FileHandle, DataLine
Position = InStr(DataLine, "time= ")
If Position > 0 Then
TimeStamp(FileCounter , 2) = Mid(DataLine, Position + 6)
FoundIt = True
Else
FoundIt = EOF(FileHandle)
End If
Wend
Close #FileHandle

Graph1(0).NumSets = multilist.ListCount
For i = 0 To multilist.ListCount - 1
Graph1(0).Legend(i + 1) = TimeStamp(i, 1) & NL & TimeStamp(i, 2)
next i
 
Strange. Now the only one that shows up is the second file that is opened.

You don't need to spend anymore time on this. I will try to work with what you have done. Thank you for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top