How should I correct this to read in the data string/integer pair?
Code: Select all
READ item$, qty
PRINT item$,qty
DATA "BLUE WIDGET",10
Code: Select all
READ item$, qty
PRINT item$,qty
DATA "BLUE WIDGET",10
Code: Select all
READ item$, qty
PRINT item$,qty
DATA AS STRING "BLUE WIDGET"
DATA AS BYTE 10
First of all, thank you for the code fragment. Actually the compilation error was a real compiler error that I fixed in this evening's COLDFIX (COLDFIX v1.17 [rev. 20250207]), and I'll try to explain the rationale.
Almost. In fact, this syntax can be useful for optimizing the code produced (as long as one uses the DEFINE READ FAST directive). However, in this case one must be sure of the type one is reading, otherwise the program may break.
Code: Select all
CLS
PRINT "INVENTORY"
PRINT "---------"
WHILE NOT READ END
READ item$,qty
PRINT item$,qty;
REM qty GETS TREATED AS 0
FOR i=1 TO qty
PRINT "O";
NEXT
PRINT
REM ADDS TO TOTAL JUST FINE
total=total+qty
WEND
PRINT
PRINT "TOTAL: ";total
PRINT
PRINT "COUNT OF LAST ITEM: ";qty
REM JUST ANOTHER TEST AND qty IS STILL TREATED AS 0
FOR i=1 TO qty
PRINT "O";
NEXT
PRINT
PRINT
REM WORKS PERFECTLY IF YOU MANUALLY ASSIGN A NUMBER
qty=10
FOR i=1 TO qty
PRINT "X";
NEXT
PRINT
WAIT KEY RELEASE
END
DATA "SWORDS",10
DATA "BOWS",5
DATA "ARROWS",15
DATA "DAGGERS",8
DATA "SPEARS",6
Sorry for the problem. It was a fault of mine. I introduced a regression, in order to save space on code generation for FOR...NEXT. You need to update your compiler, since an HOTFIX has been published today for cpc target (to fix bug#1195), and I just built the one for coco3. Sandbox has been fixed, too, so you could try also on that.