QBASIC

Quick Beginner’s All-purpose Symbolic Instruction Code

Simple Input & Output programm

The first code every programmer does is “Hello world!” programm, however just writing one line of code seems to be kinda boornig, therefore I’ll present to you a bit more interesting code that shows a bit more than just simple output.

CLS
INPUT “What is your name?”; name$
INPUT “How old are you?”; age
PRINT “Hello “, name$ , “! It is nice to see a “, age , ” year old person interested in old language!”
END

Few Operators

Writing just text sometimes can be really booring, therefore let’s play with some operators and make an interesting programm that actually does something. I’ll use GOTO , FOR, WHILE, UNTILL in one programm.
IIt also uses elements such as IF, ELSE.
If you have any questions, feel free to post them in Blog.

Click the Code tab to wiev the full code of the mentioned programm.
Code

CLS
Begining:
INPUT “Input a number from 2 to 9 please: “, X
IF X > 1 THEN GOTO 2
ELSE GOTO Begining
2 IF X < 10 THEN GOTO firstpart
ELSE GOTO Begining
firstpart:
GOTO  1
PRINT “You don’t see this line!”
‘First, let’s use the For Operator
1 FOR i = 0 to 4 STEP 0.5
y = i * X
PRINT “Current value: “, y
NEXT i
PRINT “Now we have the variable y and it’s value is: “, y
‘Now we move on with while operator
DO
y = y +1
PRINT “Current y value: “, y
LOOP WHILE y < 40
DO UNTIL y = 60
y = y + 1
PRINT “Y current value: “, y
LOOP
PRINT “Your input was “, x , ” and with this code we made a y value: “, y
PRINT “Good work!”
END

Writing data in text files.

So far we got some nice data displayed on screen, But what if we want to show the output to our friend, for thsi purpose we write the output in a .txt file, and here’s how it’s done.

Code

OPEN “C:\Qb\Prog\File.txt” FOR INPUT AS #1
FOR i = 0 TO 5
INPUT #1, x
INPUT #1, kvsx
PRINT x, kvsx
IF EOF(1) THEN GOTO finish
NEXT i
finish:
CLOSE #1
END