The first lesson was for displaying messages on the screen. Now in this one, we will tray to get messages or numbers from keyboard.
The screen is called " standard out put " and the keyboard is called "standard input".
To enter messages from the keyboard we need a place in memory to store it, this place must have an address. In qbasic, every message address must ended with "$" sign (mean string), the address can be anything you choose, but not begin with number.
Example:
First we command the computer to display message on the screen, telling to the user that he wants him to enter message, the user tapes on the keyboard and end with pressing Enter. Then the message entered will be stored in memory and the message$ will be its address, after that we will display the message entered after telling the user what he will display in the screen:
"the message you have entered was:"
PRINT message$ display the message stored in memory at address message$.
In this address the message will be stored till the program end, or till we change it with another INPUT.
Like the program below:
At anytime you want to display mess1$, the messages will be the second one, because the second take the first one's place in memory.
And the first message was lost, you'll never find it .
The mess$ will be called a variable, because we can change it at anytime we want.
The INPUT instruction can do what PRINT do, I mean that INPUT will display messages in screen .
Look at this program:
This program is equivalent to this one:
As you see, we used a semicolon between the message that we want to display and the mess$ variable.
What about numbers entering?
Answer in program:
As you see, to store number in memory, you mustn't use the "$" sign .
The user will enter a number that will be stored with a address, then he will enter the second which will be stored with b address, after that the computer add a to b and store the result in c address, finally we will display what is in c address (the result).
AS you saw, the computer can do the maths.