I am trying to open a file and read the lines in the file to a variable that will then be written to the screen. The script will open a different file depending on the value of the loop. If the file does not exists it will display a message stating so.
without the if statement I get Error 5: Invalid Identifier. I did not know what this meant when I read the definition in the help files. any ideas
I don't know why, but the script will not open the files. the files exists in the directory, and spelling is correct, any idea why it cannot open/find the files?
here is the code
string strCrawl ;Message displayed on the screen
string strCounty ;Variable for which county is displayed
string strLineBuffer ;Data in file
integer intX ;Number for the loop
integer intLength ;Length of the string
for intX = 1 upto 13
;-------------------------------------------------------
if intX == 1
strCounty = "V:\StormWarning\TVDir\Adams.txt"
elseif intX == 2
strCounty = "V:\StormWarning\TVDir\Berks.txt"
elseif intX == 3
strCounty = "V:\StormWarning\TVDir\Cumberland.txt"
elseif intX == 4
strCounty = "V:\StormWarning\TVDir\Dauphin.txt"
elseif intX == 5
strCounty = "V:\StormWarning\TVDir\Juniata.txt"
elseif intX == 6
strCounty = "V:\StormWarning\TVDir\Lancaster.txt"
elseif intX == 7
strCounty = "V:\StormWarning\TVDir\Lebanon.txt"
elseif intX == 8
strCounty = "V:\StormWarning\TVDir\Mifflin.txt"
elseif intX == 9
strCounty = "V:\StormWarning\TVDir\Perry.txt"
elseif intX == 10
strCounty = "V:\StormWarning\TVDir\Schuylkill.txt"
elseif intX == 11
strCounty = "V:\StormWarning\TVDir\Snyder.txt"
elseif intX == 12
strCounty = "V:\StormWarning\TVDir\York.txt"
else
exit
endif
;-------------------------------------------------------
;---This process is repeated for each county------------
if fopen 0 strCounty READ TEXT ;Open file for read only, if it exists.
while not feof 0 ;Loop while not end of file.
fgets 0 strLineBuffer ;Get line from file.
strlen strLineBuffer intLength ;Caluclate the length of the line
substr strCrawl strLineBuffer 1 (intLength - 1) ;Remove the Quotes
strcat strCrawl " " ;need to remove the quotes and add a space between rows
endwhile
fclose 0
else
errormsg "Couldn't open file `"%s`"." strCounty
endif
;-------------------------------------------------------
endfor Jason Meckley
Database Analyst
WITF
without the if statement I get Error 5: Invalid Identifier. I did not know what this meant when I read the definition in the help files. any ideas
I don't know why, but the script will not open the files. the files exists in the directory, and spelling is correct, any idea why it cannot open/find the files?
here is the code
string strCrawl ;Message displayed on the screen
string strCounty ;Variable for which county is displayed
string strLineBuffer ;Data in file
integer intX ;Number for the loop
integer intLength ;Length of the string
for intX = 1 upto 13
;-------------------------------------------------------
if intX == 1
strCounty = "V:\StormWarning\TVDir\Adams.txt"
elseif intX == 2
strCounty = "V:\StormWarning\TVDir\Berks.txt"
elseif intX == 3
strCounty = "V:\StormWarning\TVDir\Cumberland.txt"
elseif intX == 4
strCounty = "V:\StormWarning\TVDir\Dauphin.txt"
elseif intX == 5
strCounty = "V:\StormWarning\TVDir\Juniata.txt"
elseif intX == 6
strCounty = "V:\StormWarning\TVDir\Lancaster.txt"
elseif intX == 7
strCounty = "V:\StormWarning\TVDir\Lebanon.txt"
elseif intX == 8
strCounty = "V:\StormWarning\TVDir\Mifflin.txt"
elseif intX == 9
strCounty = "V:\StormWarning\TVDir\Perry.txt"
elseif intX == 10
strCounty = "V:\StormWarning\TVDir\Schuylkill.txt"
elseif intX == 11
strCounty = "V:\StormWarning\TVDir\Snyder.txt"
elseif intX == 12
strCounty = "V:\StormWarning\TVDir\York.txt"
else
exit
endif
;-------------------------------------------------------
;---This process is repeated for each county------------
if fopen 0 strCounty READ TEXT ;Open file for read only, if it exists.
while not feof 0 ;Loop while not end of file.
fgets 0 strLineBuffer ;Get line from file.
strlen strLineBuffer intLength ;Caluclate the length of the line
substr strCrawl strLineBuffer 1 (intLength - 1) ;Remove the Quotes
strcat strCrawl " " ;need to remove the quotes and add a space between rows
endwhile
fclose 0
else
errormsg "Couldn't open file `"%s`"." strCounty
endif
;-------------------------------------------------------
endfor Jason Meckley
Database Analyst
WITF