Page 1 of 1
How to loop till the end of file using a server routine?
Posted: Tue Apr 15, 2008 5:56 am
by pradeepkumar_b@thbs.com
I am trying to return the records till the end of a sequential file using a server routine. I am able to do this giving using "for next" for fixed no of record but not for whole file. Also tried with " do while" but I am unable to figure out how to give condition for end of loop. thanx in advance.
seeking help please
Posted: Tue Apr 15, 2008 6:14 am
by BugFree
You will have to use a combination of ReadSeq and STATUS() functions to loop through the file. STATUS returns 1 when it reaches the end of file. So that will be the condition for the loop.
Posted: Tue Apr 15, 2008 6:34 am
by ray.wurlod
Code: Select all
Ans = ""
OpenSeq pathname To filevariable
Then
Loop
While ReadSeq Line From filevariable
Ans<-1> = Line
Repeat
End
CloseSeq filevariable
do while
Posted: Tue Apr 15, 2008 6:43 am
by pradeepkumar_b@thbs.com
can u please tell me the syntax of do while here..i am unable to figure out..i am gettingl lot of errors
Posted: Tue Apr 15, 2008 6:44 am
by chulett
Post your code.
Posted: Tue Apr 15, 2008 6:46 am
by pradeepkumar_b@thbs.com
THANX FOR UR RESPONSE
Posted: Tue Apr 15, 2008 7:51 am
by chulett
Or not. All such syntax is spelled out in the BASIC.pdf manual installed on your PC.
Posted: Tue Apr 15, 2008 10:25 pm
by pradeepkumar_b@thbs.com
i am using following code for the parsing sequential file. Its not giving output it is going for infinite loop.. Can u pls help me out here.
ParameterPathName = WorkDir : "\" : ParameterKey : ".txt"
OpenSeq ParameterPathName To hFile Then
LOOP WHILE STATUS()= 0
ReadSeq ParameterRecord From hFile Then
Call DSLogInfo(ParameterRecord , "ReadParameterFileRecord")
End Else
Call DSLogWarn("Unable to read parameter file (" : ParameterPathName : ") (" : Status() : ")", "ReadParameterFileRecord")
ParameterRecord = @NULL
End
Ans = ParameterRecord
REPEAT
CloseSeq hFile
End Else
Call DSLogWarn("Unable to open parameter file (" : ParameterPathName : ") (" : Status() : ")", "ReadParameterFileRecord")
Ans = @NULL
End
Posted: Tue Apr 15, 2008 11:36 pm
by ray.wurlod
Status() is still set to 0 at the end of the file. You need to exit from your loop when the ELSE clause of the ReadSeq statement is taken. One way is an EXIT statement. Look at the loop I posted earlier - it's much cleaner code. Just put your parsing logic between the WHILE and REPEAT statements.