QBASIC

Here is a number of mini-programs. Each program begins with the CLS statement (which clears the screen and moves the cursor to the top left hand corner).

QBasic uses the IF statement to make decisions. The IF statement always includes THEN. If the condition following the condition is true, the statement or statement block after the THEN is executed, otherwise it is ignored.

CLS
input "Enter a number";num
if num<10 then
	?"Number has only one digit.
else
	?"Number has more than one digits
end if

QBasic uses you 2 types of loops, For...Next and Do...Loop.
CLS
Do
	input a$
Loop until a$=""

CLS
For x=1 to 10
	color x
	?x
next

For...Next can use variables as its start and end points. For example,
CLS
INPUT"Enter start point of loop";Start
INPUT"Enter end point of loop";Finish
INPUT"Enter increment of loop";inc
FOR X = Start TO Finish STEP Inc
	? " x equals ";x
NEXT

For..Next can be used to display some ascii characters.
CLS
INPUT"Enter start point of loop";Start
INPUT"Enter end point of loop";Finish
FOR X = Start TO Finish 
	? chr$(x);" has an ascii code of ";x
NEXT

Arrays can be used to group different variables of the same type.
CLS
dim People$(1 to 5)
for x=1 to ubound(People$)
	?"Enter person number ";x
	input People$(x)
next

CLS
do
	?"Look up a person between 1 and 5 or press enter to quit.
	input a$
	num=val(a$)
	if Num>0 and Num<=ubound(People$) then	
	?"Person number ";x;" is ";People$(Num)
	else
		?"Number entered outside range.
	endif
loop until number=0

CLS
CENTRE "This
CENTRE "is
CENTRE "centred on the row.

SUB CENTRE(a$)
LOCATE CSRLIN,40-LEN(a$)/2
? A$
END SUB

CLS
INPUT" Enter Height";h1
INPUT" Enter Width";w1
INPUT" Enter Depth";d1
Vol=GetVolume(h1,w1,d1)
?"Volume is ";vol

Function GetVolume(h,w,d)
GetVolume=h * w * d
END FUNCTION




Back to Basic Page