|
Post by Steve on Mar 19, 2003 0:51:38 GMT
I tried to write a simple QBasic program to edit a data file I have which is about 4800 records long. I keep getting an "out of string space" error message when I run it (though it works on a shorter version of the input file). Any ideas on how to fix this? (code pasted below) ------------------------------ CLS CLEAR , , 2200 DIM ifile AS STRING * 12, ofile AS STRING * 12 DIM field1 AS STRING * 14, field2 AS STRING * 1, field3 AS STRING * 64 DIM record$(5000) INPUT "Input filename:"; ifile OPEN ifile FOR INPUT AS #1 INPUT "Output filename:"; ofile OPEN ofile FOR OUTPUT AS #2 i% = 1 DO WHILE NOT EOF(1) LINE INPUT #1, record$(i%) field1 = LEFT$(record$(i%), 14) field2 = MID$(record$(i%), 15, 1) field3 = RIGHT$(record$(i%), 64) IF field2 = " " THEN PRINT #2, field1; "0"; field3 ELSE PRINT #2, record$(i%) END IF i% = i% + 1 LOOP CLOSE #2 END
|
|
|
Post by Qwiz on Mar 23, 2003 2:50:34 GMT
You are running out of string space because the program is attempting to read the entire file into memory via the string array record$(). Since your program only works on one record at a time, there is no need to store the entire input file in memory. Eliminate the string array and just use a simple string variable to hold the current input record.
DO WHILE NOT EOF(1) LINE INPUT #1, record$ field1 = LEFT$(record$, 14) field2 = MID$(record$, 15, 1) field3 = RIGHT$(record$, 64) IF field2 = " " THEN PRINT #2, field1; "0"; field3 ELSE PRINT #2, record$ END IF
You can also eliminate the index variable i% that goes with the array.
Qwiz
|
|
|
Post by Tomy on Jun 7, 2015 17:22:29 GMT
<IMG SRC = "Test.gif">
|
|