SECTION E - PRIMER FILE PRIMER.E INPUT FROM THE KEYBOARD *********************** Most programs require some information or action from the viewer, even if it is only to respond to a 'Press any key to continue' request. PRIMER looks at the INPUT,LINE INPUT and INKEY$ commands An easy way to use the INPUT command is to put it in the form: 10 INPUT " What is your first name ?"; name$ The characters between the quote marks will print on the screen to invite a response from the operator, who will type in an answer then press RETURN . The name will be stored as the variable name$, which can then be used as you wish in the program. Name$, as you can see, is a string variable but if the answer to an INPUT statement is expected to be a number then the variable should be of the numeric type. eg. z or t% ( as explained in section c ) Another way to use the same command is: 10 PRINT " What is your first name ? " 20 INPUT name$ This method may appear to be long-winded but it's appearance when run may be to your liking for some programs. Check it on the next listing. It comes into it's own when making a multiple choice menu. INPUT can be used to store more than one variable, but this is not recommended as it requires more application from the operator. The command would take the form ; 50 INPUT "Name your choices of fruit 1st/2nd/3rd "; a$,b$,c$ Note that the three names can be stored in variables a$,b$ and c$ and used separately, but unfortunately it involves the operator typing the three choices with a comma between, otherwise the input will not be accepted and you are faced with the message 'Redo from start', which is a standard BASIC error message.It is usually preferable to use one INPUT line for each variable. 70 PRINT "Name your choice of fruit in order of preference" 80 INPUT "First choice" ,first$ 90 INPUT "Second choice " , second$ etc. Punctuation plays it's part as usual in the syntax. There must be a comma or a semicolon between the prompt in quotes and the variable. A semicolon causes a question mark to be printed , the comma does not. Check this on the next listing. A similar command, used in similar ways, is LINE INPUT. This allows the input of lines of script, including commas,which are rejected by INPUT. Another useful routine involves the function INKEY$ 40 PRINT" Press any key to continue " 45 WHILE INKEY$="": WEND The familiar 'Press any key to continue' routine is done with the help of the INKEY$ function. INKEY$ monitors the keyboard for a character to be pressed,and reports on it. This information can be used by the computer in various ways. In line 45 above there is a WHILE...WEND loop .We haven't covered this yet, but it is sufficient to know that line 45 will hold up the program until the statement INKEY$ = "" is not true. "" is a pair of double quotes with nothing in between and is known as a null string. (null = nil, nowt, nothing or zilch, depending on your college) When a key is pressed INKEY$ ="" is no longer true as now INKEY$ = 'the key value pressed' and so the program can proceed. You don't need to bother with the theory unless you wish - just use the routine. INKEY$ can also be made to hold up a program until a particular key is pressed. Use the routine : 80 PRINT "Press C to continue.' 90 WHILE INKEY$<>C OR INKEY$<>c: WEND In line 90 a loop is formed by WHILE...WEND The sign <> means 'is not equal to ' , so when either upper case or lower case c is pressed line 90 stops looping and the program continues. This routine can be modified yet again to use keys or characters which do not appear on the keyboard: 120 PRINT "Press RETURN to continue" 130 WHILE INKEY$<>CHR$(13): WEND This example is the same as the previous one except for the CHR$(13) This brings into play the ASCII code system which is recognised by your computer. Each character and function has a number allocated to it, and a full table can be seen in the PCW manual, page 113. CHR$ converts the number to it's ASCII character ,and as 13 represents RETURN ,bingo. Other useful numbers for this purpose are: 27 = EXIT , 32 = SPACE BAR End of file PRIMER.E be