Authors
Publication
Pub Details
Date
Pages
BASIC Terms
QUESTION: What is the STR$ function used for?
ANSWER: The argument (the expression following the keyword) of STR$ must be a number or a variable that stands for a number (like X). The STR$ takes that number and changes it to a string and assigns it to a string variable (like X$). It can now be sliced or manipulated as a string. This would be a good way to look for the decimal and line it up for proper printing.
QUESTION: How do you use the commands “IN” and “OUT”?
ANSWER: These are usually used in machine code but Sinclair added them to the keyboard as part of BASIC. They are used to send and receive data on one of the 256 “PORTS” which are available. Usually, these ports are wired to external devices like modems and printers. As an example, the AERCO printer interface is wired to port 127. Data can be sent from a program to the printer by the command OUT 127, data. To keep things running smoothly, we follow with an IN 127. This can take the form LET B=IN 127 or if you don’t need the IN data, simply RANDOMIZE IN 127. Try the following program without loading the printer driver program. Line 60 sends the carriage return.
10 INPUT LINE A$
20 FOR I = 1 TO LEN A$
30 LET A = CODE A$(i)
40 OUT 127,A: RANDOMIZE IN 127
50 NEXT I
60 OUT 127,13: RANDOMIZE IN 127
70 GO TO 10
Normally we would need to check a “busy line” before sending another letter, but BASIC is so slow compared to machine code that this is not needed in this case.
QUESTION: Can I delete a variable once it has been assigned?
ANSWER: Of course, CLEAR deletes all the variables, but I assume you meant just one variable at a time. This can be done with variables that were created by the DIMension function. Let’s say you entered DIM X(35). Later you want to delete the X variable and recover the memory space. Just enter DIM X(0). This results in an error message because you cannot DIMension for zero. Before the computer gets around to checking for that it has already wiped out the old X variable. Within a program you can handle the error with an ON ERR CONTINUE before the DIM and ON ERR RESET after it.