Site hosted by Angelfire.com: Build your free website today!

Reinier's QBasic page: Lesson 2: LET

This is another very important command in QBasic.
LET Variable=numerical value
This assigns the numerical value to the Variable, to be used later in the program.

Example #1:
LET A=13

Output:
Nothing is displayed on the screen, but whenever A is used in the program, 13 is understood unless A changes.

Example #2:
LET A=A+1

Output:
Nothing is displayed on the screen, but A now equals 14.

One important thing to know, is that LET is hardly ever used in QBasic programs, because you can leave LET out. For example, if you write A=13, it means the same thing as LET A=13.

The variables you can use can have letters, both uppercase and lowercase, and numbers, although the name can't begin with a number. There are probably some other acceptable things that I'm forgetting here, but I'll have to check those.


LET Variable$="String"
This assigns the variable the text in the string. The $ has to be there as a way to tell the computer a string is coming up.

Example:
LET A$="Reinier" or A$="Reinier"

Output:
Guess what!!! Nothing is displayed on the screen, but A$ is now the string containing Reinier.


PRINT and LET
Here is our first program!!!

Program:
10 A=13
20 B$="QBasic"
30 PRINT "Reinier is";A;"years old and he enjoys ";B$;"."
40 END

Output:
Reinier is 13 years old and he enjoys QBasic.

Line numbers are not really important, and I could've written the same program with the same output without the line numbers. I could also have some of the lines have line numbers and the rest not. The line numbers are just easy for GOTO and GOSUB, to be explained in a later lesson.

END is not really nessecary in this program. The program would end anyway because there are no commands after line 30 in this case. END serves a purpose in the middle of a program if you want to stop the program right there.

End of lesson 2.


Return to lessons
Return home