GW-Basic stands for Gee-Whiz Beginners’ All-Purpose Symbolic Instruction Code and Graphics and Windows Beginner’s All-Purpose Symbolic Instruction Code.
It is a fundamental Computer programming language for beginners who want to become an expert computer programmers.
How to Open GW-Basic?
Click on the Start, type basic, if GW-Basic will already be installed then click on it otherwise install it.
Remember for different windows, gw-basic language installs with a different name.
As for windows 7 or higher, it is PC-BASIC.
How to type programme in GW-Basic?
There are two methods to type the programme in GW-Basic.
- Direct Method
- Indirect Method
Direct Method in GW-Basic
In the direct method, we type the programme without line numbers and get the result just after pressing the enter key.
For example.
PRINT 34+45 [Enter]
79
OK
Indirect Method in GW-Basic
In the indirect method, we type the programme with line numbers and get the result after executing the programme by using the RUN command or pressing the F2 key
For example
10 PRINT 34+45 [Enter]
RUN [Enter] or F2
79
OK
First Programme in GW-Basic
10 PRINT “Rana Mehtab Alam” [Enter]
20 END
RUN [Enter] or F2
Rana Mehtab Alam
OK
Numeric and String values in GW-Basic
Numeric value is (0 ~ 9)
While string value is anything which you type in “quotation marks”.
10 CLS
20 PRINT 99
30 PRINT “Lunar Computer College”
40 END
RUN [Enter] or F2
99
Lunar Computer College
OK
Another example to learn about numeric and string values
10 CLS
20 PRINT “99 + 45”
30 PRINT 20 + 50
40 END
RUN [Enter] or F2
99 + 45
70
In the above example, you will notice that the values under the quotation marks are displayed as it is [20 PRINT “99 + 45”], while you get the result of the values that are without quotation marks [30 PRINT 20 + 50].
Counting from 1 to Infinity in GW-Basic
10 CLS
20 N = 0
30 N = N + 1
40 PRINT N
50 GOTO 30
RUN [Enter] or F2
1
2
3
.
.
.
To break the counting press Ctrl + Pause / Break
List of GW-Basic commands and statements with examples.
PRINT
CLS
GOTO
ON GOTO
IF THEN ELSE
FOR NEXT
FOR NEXT STEP
READ DATA
LOCATE
LEN
VARIABLES
Use of : ; ,
GW-BASIC GRAPHICS
Shop Billing Software in GW-Basic using DIM
Digital Clock in GW-Basic
Result Sheet
FILES
NEW
SAVE
LOAD
PLAY
What is PRINT in GW-Basic?
To get the output in GW-Basic
PRINT “Rana”
10 PRINT “Rana”
What is the use of CLS in GW-Basic?
Clear the Screen
Use this command at the start line of the programme to get the output after clearing the screen.
10 CLS
How to use GOTO in GW-Basic?
To go to the specific line number
10 CLS
20 PRINT “Rana Mehtab Alam”
30 GOTO 20
after executing the above computer programme computer will type Rana Mehtab Alam continuously till you stop it by pressing Ctrl + Pause Break
How to use ON GOTO in GW-Basic?
to go to the specific line number conditionally from 1 to so on ….
10 REM ON GOTO Programmed by Rana Mehthab Alam
20 CLS
30 INPUT “Enter first value”;FV
40 INPUT “Enter second value”;SV
50 PRINT “1 :- + (Addition)”
60 PRINT “2 :- – (Subtraction)
70 PRINT “3 :- * (Multiplication)
80 PRINT “4 :- / (Division)
90 INPUT “Select from 1 to 4”;S
100 ON S GOTO 110,130,150,170
110 PRINT FV;”+”;SV;”=”;FV+SV
120 END
130 PRINT FV;”-“;SV;”=”;FV-SV
140 END
150 PRINT FV;”*”;SV;”=”;FV*SV
160 END
170 PRINT FV;”/”;SV;”=”;FV/SV
180 END
Ok
RUN
Enter first value? 50
Enter second value? 20
1 :- + (Addition)
2 :- – (Subtraction)
3 :- * (Multiplication)
4 :- / (Division)
Select from 1 to 4? 3
50 * 20 = 1000
Ok
What is the use of IF THEN ELSE in GW-Basic?
to set the conditions in the programme.
10 CLS
20 LET N = 0
30 LET N=N+1
40 PRINT N
50 IF N<10 THEN GOTO 30 ELSE GOTO 60
60 END
after executing the above programme computer will display 1 to 10 numbers in this way.
RUN
1
2
3
4
5
6
7
8
9
10
OK
What is the use of FOR NEXT Loop in GW-Basic?
We use this loop to repeat the process to a specific time given in the loop.
5 REM Display from 1 to 5
10 FOR K = 1 TO 5
20 PRINT K
30 NEXT K
40 END
RUN
1
2
3
4
5
How to use FOR NEXT with specific STEP?
2 CLS
5 REM odd number from 1 to 9 with for next
10 FOR K = 1 TO 10 STEP 2
20 PRINT K
30 NEXT K
40 END
RUN
1
3
5
7
9
OK
How to use READ DATA in GW-Basic?
read the data from data and generate the output.
10 READ A,B
20 T=A+B
30 PRINT A;”+”;B;”=”;T
40 END
50 DATA 9,8
RUN
9 + 8 = 17
What is the use of LOCATE in GW-Basic?
to type at a specific location on the screen.
There are 40 columns and 24 rows in SCREEN 1 and 80 columns and 24 rows in SCREEN 2 : SCREEN 0
If I want to type Rana Mehtab Alam in the center of the screen in SCREEN 2: SCREEN 0: of GW-Basic language programme.
10 CLS
20 LOCATE 32,12 : PRINT”Rana Mehtab Alam”
30 END
What is the use of LEN in GW-Basic?
is to use to count the number of characters in a word or sentence.
?LEN(“Rana Mehtab Alam”)
16
Note: In GW-Basic language we can use
? instead of a PRINT statement.
Types of Variables in GW-Basic
There are two types of variables.
- Numeric Variables
- String Variables
Numeric Variables
It is also called a simple variable in which we can store a numeric value into a variable.
x = 99
x is variable while 99 is the value.
String Variable
In string variable, we store non-numeric values into the variable.
x$=”This is string value”
Note:- you can use a to z or any word except reserve words like print list load for variables
Types of Variables in GW-Basic
There are two types of variables.
- Numeric Variables
- String Variables
Numeric Variables
It is also called a simple variable in which we can store a numeric value into a variable.
x = 99
x is variable while 99 is the value.
String Variable
In string variable, we store non-numeric values into the variable.
x$=”This is string value”
Note:- you can use a to z or any word except reserve words like print list load for variables
Use of comma (,), semicolon (;) and colon (🙂
use of colon ( : ) in GW-Basic
To type two or more two statements in a single line of GW-Basic input programme.
For example
10 CLS
20 LET A= 0
30 LET B=0
We can type upper lines in a single line using colon (:)
10 CLS : LET A= 0 : LET B=0
use of a comma (,) in GW-Basic
By using (,) in the input programme we can get output in columns.
10 CLS
20 PRINT “RANA”,
30 PRINT “MEHTAB”,
40 PRINT “ALAM”
RUN [Enter] or F2
RANA MEHTAB ALAM
OK
use of semicolon (;) in GW-Basic
By using (;) in the input programme we can get output in a row.
10 CLS
20 PRINT “RANA”;
30 PRINT “MEHTAB”;
40 PRINT “ALAM”
RUN [Enter] or F2
RANAMEHTABALAM
OK
GW-BASIC GRAPHICS
First, change the screen in SCREEN 1 in GW-Basic, then you can draw lines, circles.
CIRCLE (column,row),radius
In SCREEN 1 total number of columns, 320 and rows 200 for drawing in GW-Basic.
How to draw a circle in GW Basic
To draw a circle in the middle of the screen with a 50 radius
10 CLS: SCREEN 1
20 CIRCLE (160,100),50
RUN
LINE (START COL,START ROW)-(END COL,END ROW)
10 LINE(10,30)-(40,50)
Shop Billing Software in GW-Basic
10 CLS
20 DIM Q,R,A
30 INPUT “Item
40 INPUT “Item”;I$(S)
50 INPUT “Rate”;R(S)
60 INPUT “Quantity”;Q(S)
70 A(S)=R(S)*Q(S)
72 SUM=SUM+A(S)
80 INPUT”More”;M$
90 IF M$=”y” THEN GOTO 90 ELSE GOTO 95
95 LET S=S+1:GOTO 30
100 CLS
110 PRINT”S/No”,”Item Name”,”Quantity”,”Rate”,”Amount”
120 FOR K=0 TO S
130 PRINT K+1,I$(K),Q(K),R(K),A(K)
140 NEXT K
150 PRINT:PRINT “Total Bill =”,,SUM
160 INPUT”Paid by customer “,PBC
170 LET BAL =SUM-PBC
180 PRINT “Balance =”,,BAL
190 IF BAL<0 THEN G$=”Change return to customer”:GOTO 300
200 IF BAL>0 THEN G$=”Bill is pending from customer”:GOTO 300
210 G$=”Bill Paid Successfuly”
300 PRINT G$
Ok
Digital Clock in GW-Basic
10 REM Programmed by Rana Mehtab Alam.
20 REM if you have any problem contac to 03004467226
30 CLS
40 INPUT “Enter Current hours”;H
50 INPUT “Enter Current minutes”;M
60 INPUT “Enter Current seconds”;S
70 CLS
80 LOCATE 8,10 :PRINT”Lunar Digital Clock”
90 LOCATE 9,10 :PRINT”*=*=*=*=*=*=*=*=*=*”
100 LOCATE 10,14:PRINT”HR : MN : SC”
120 LOCATE 11,18:PRINT M
130 LOCATE 11,23:PRINT S
140 LOCATE 12,10 :PRINT”*=*=*=*=*=*=*=*=*=*”
150 LET S=S+1
160 FOR T = 1 TO 25000!:NEXT T
170 IF S<60 THEN GOTO 110 ELSE GOTO 180
180 LET S=0:LET M=M+1
190 IF M<60 THEN GOTO 110 ELSE GOTO 200
200 LET S = 0 : LET M = 0 :LET H=H+1
210 IF H<12 THEN GOTO 110 ELSE GOTO 220
220 LET S=0:LET M=0:LET H = 1
230 GOTO 110
240 REM Programmed by Rana Mehtab Alam.
250 REM if you have any problem contact to 03004467226
260 END
Ok
Result Sheet Programme in GW-Basic
10 CLS
20 INPUT “Student Name”;SN$
30 INPUT “Class”;CL$
40 CLS
50 INPUT “Total Marks in English”;ENG
60 INPUT “Obtain Marks in English”;E
70 INPUT “Total Marks in Maths”;MTH
80 INPUT “Obtain Marks in Maths”;M
90 INPUT “Total Marks in Urdu”;UR
100 INPUT “Obtain Marks in Urdu”;U
120 INPUT “Obtain Marks in Physics”;P
130 INPUT “Total Marks in Chemistry”;CHE
140 INPUT “Obtain Marks in Chemistry”;C
150 LET ST = ENG+MTH+UR+PHY+CHE
160 LET OT=E+M+U+P+C
170 LET A=OT/ST*100
180 IF A>=80 AND A<=100 THEN G$=”A+”:GOTO 250
190 IF A>=70 AND A<80 THEN G$=”A”:GOTO 250
200 IF A>=60 AND A<70 THEN G$=”B”:GOTO 250
210 IF A>=50 AND A<60 THEN G$=”C”:GOTO 250
220 IF A>=40 AND A<50 THEN G$=”D”:GOTO 250
230 IF A>=33 AND A<40 THEN G$=”E”:GOTO 250
240 LET G$=”Fail”
250 IF G$=”A+” THEN R$=”Most Excellent” :GOTO 320
260 IF G$=”A” THEN R$=”Excellent”:GOTO 320
270 IF G$=”B” THEN R$=”Very Good”:GOTO 320
280 IF G$=”C” THEN R$=”Good”:GOTO 320
290 IF G$=”D” THEN R$=”Nice”:GOTO 320
300 IF G$=”E” THEN R$=”Average”:GOTO 320
310 LET G$=”Bad”
320 CLS
325 PRINT “Name”,n$
327 PRINT “Class”,cl$
330 PRINT “Subject”,”Total”,”Obtained”
340 PRINT “English”,ENG,E
350 PRINT “Math”,MTH,M
360 PRINT “Urdu”,UH,U
370 PRINT “Physics”,PHY,P
380 PRINT “Chemistry”,CHE,C
390 PRINT “Avg Marks =”;A
400 PRINT “Grades =”;G$
410 PRINT “Remarks=”;R$
420 END
Table Learning Software in GW-Basic
10 CLS
20 INPUT “WHICH TABLE DO YOU WANT”;T
30 INPUT “WHERE TO START”;S
40 INPUT “WHERE TO END”;E
45 CLS
50 PRINT “TABLE OF”;T
60 PRINT “—————“
70 PRINT T;”X”;S;”=”;T*S
80 S=S+1
90 IF S<=E THEN GOTO 70 ELSE GOTO 100
100 PRINT “—————“
120 INPUT “DO YOU WANT MORE TABLES…Y/N”;T$
130 IF T$=”Y” OR T$=”YES” OR T$=”yes” OR T$=”Yes” OR T$=”y” THEN GOTO 10 ELSE GOTO 140
140 PRINT “THANKS”
150 END
FILES
call the list files and directories.
NEW
to erase the programme from the computer’s memory
SAVE
to save the current programme
SAVE”FileName
F4 for Save
Note: Maximum 8 characters for save file name in GW-Basic witout spacing.
LOAD
to load the saved programme
LOAD”FileName
F3 for Load
PLAY
to play the music in GW-Basic
10 PLAY “abcdefg”
Happy Birthday in GW-Basic with play command
10 CLS
20 PLAY “C8C8DCFE”
30 END