Posted Aug 26 2009 I have a short program that attempts to read in a set of files (using READ/DATA statements in a loop). In some cases, one or more of the files may not exist and will need to be skipped. What is the preferred method of handling the errors generated by attempting to open non-existing files that doesn't involve GOTO's and line numbers? Here is the code:
CLS
DO WHILE (LEN(r$) <> 6)
INPUT "Enter Date to Summarize YYMMDD (Enter only to Quit) ", r$
IF r$ = "" THEN END
LOOP
f$ = "20" + r$ + ".TXT"
OPEN f$ FOR OUTPUT AS #1
DATA WW,FI,CU,SE,IS,OS,PC,PU,SH
FOR x = 1 TO 9
READ pref$
ff$ = pref$ + r$ + ".TXT"
OPEN ff$ FOR INPUT AS #2
DO WHILE NOT EOF(2)
LINE INPUT #2, rr$
PRINT #1, rr$
z = z + 1
LOCATE 3, 5: PRINT z
LOOP
CLOSE #2
NEXT x
CLOSE : END
The portion in question is:
OPEN ff$ FOR INPUT AS #2 |