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

Cannot open file? I do not understand

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
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
 
Jason, I took your script, set c:\autoexec.bat as the first file to open, and the fopen command was successful for me. Does the machine (or user) you are running the script on able to access these files in Windows Explorer successfully? If the filenames and paths are entered in correctly, that would be my first guess at least. aspect@aspectscripting.com
 
everyobdy involved in this project has access to the V:\ drive. I attempted to open a file up on my C:\ drive and that did not open either.

according to the help files 2 things are required for fopen to work
id: The file id to assign to the file. This value must be greater than or equal to zero.
filespec: A valid file specification. If no path is specified, the current User Path is assumed.

What do they mean by "current User Path?" Does the file ID have to change for each file, or can the ID stay the same for all 12 files?

Is there any default system setting that needs to be in place for fopen to work properly? If there is I may have modified that during setup, unknowingly?

Thank you for your assistance
Jason Meckley
Database Analyst
WITF
 
Good news, the problem is solved! the error was produced by the file extention. I have my file extentions hidden. so on my screen it read "Adams.txt". When in actuality it was "Adams.txt.txt".

It's always the small things that we overlook:) Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top