Sunday, June 2

TAB Function

The TAB function spaces to position on the screen.
Syntax
LN TAB (n)
Where,
LN     :  Line Number
n         :  number of spaces

  • Space 1 is the left most position.
  • n must be within the range of 1 to 255.
  • if the current print position is already beyond space n, TAB goes to that position on the next line.
  • TAB should be used with PRINT statement.

Example 2

1.  100  PRINT "NAME" TAB (15); "ADDRESS"; TAB(40); "PHONE NO"
2.  50    PRINT "ROLL NO." TAB(30); "MARKS OBTAINED"
Use of TAB function in the program

CS 5.3 Display on the screen the TAB function

Ok
LIST
5      REM Learning use of TAB function
10    PRINT "NAME" TAB(25) "FEE"
15    PRINT "----"      TAB(25) "---"
20    READ A$,B$
30    PRINT A$ TAB(25) B$
40    DATA "SUMA SHAH" , "RS.  500.00"
50    END
Ok
RUN
NAME                        FEE
----                              ---
SUMA SHAH            RS. 500.00
Ok

CS 5.4 Display on the screen for TAB statement
Ok
LIST
10  REM Result of First terminal Exam
20  REM of a student
30  PRINT "ENTER NAME, ROLL & MARKS"
40  INPUT "NAME :-"N$
50  INPUT "ROLL NO.:-" R
60  INPUT " MARKS IN ENGLISH" ; E
70  INPUT "MARKS IN NEPALI" ; N
80  INPUT "MARKS IN SCIENCE" ; S
90  INPUT "MARKS IN COMPUTER" ; C
100  PRINT "NAME" ; TAB(30) ; N$
103  PRINT "ROLL NO." ; TAB(30) ; R
106  PRINT 
110  PRINT "ENGLISH" ; TAB (30) ; E
120  PRINT "NEPALI" ; TAB(30) ; N
130  PRINT "SCIENCE" ; TAB(30) ; S
140  PRINT "COMPUTER" ;TAB(30) ; C
150  PRINT
160  PRINT "TOTAL" ; TAB(30) ; E+N+S+C
170  END
Ok
          
                  
       

Wednesday, May 29

Reading and Printing

Introduction

In a computer program it is often necessary to supply data to the program and print the result. This is done by input and output statements. In a BASIC program data can be supplied by INPUT, READ,DATA, RESTORE statements and printed with PRINT and LNPRINT statement.
PRINT Statement
The PRINT statement is used to output a display on the screen.
Syntax
LN PRINT [list of expression] [;] 
? [list of expression] [;] 
where,
LN  :  Line Number
list of expressions  :  value of expressions which is to be displayed
Points to Remember :

  • if list of expression is omitted , blank line is displayed.
  • if list of expression is included , values of expression are displayed.
  • Expression in the list may be numeric and / or string expressions, separated by comma or semicolons.
  • String constant in the list must be enclosed in double question marks.
  • ? (question mark) may be used in place of the word PRINT.
Example 1
Follwing are some valid PRINT statements :
1. 5 PRINT A
2. 10 PRINT 
3. 15 PRINT A+B, C
4. 20 PRINT "C, " , C, " A+B"; T
5. 25 PRINT A $+ B $, C $
6. 30 PRINT {28.34 - 11.28}^9*(1.5 E5)

Use of PRINT statement in the programs
CS 5.1 Display on the screen for PRINT statement

Ok
LIST
10   REM Learning the use of PRINT statement
20   REM  Values of two numbers X and Y
30   X=20
40   Y=10
50   REM Addition of two numbers X and Y
60   A=X+Y
70   PRINT X
80   PRINT Y
90   PRINT A
100 END
Ok
RUN
20
10 
30
Ok

CS 5.2 Dislpay on the screen for PRINT statement

Ok
LIST
10  REM Learning the use of PRINT statement
20  REM Values of the numbers X and Y
30  X=20
40  Y=10
50  REM Addition of two numbers X and Y
60  A=X+Y
70  PRINT "Value of X ="; X
80  PRINT " Value of Y="; Y
90  PRINT "Addition of X and Y ="; A
100 END
Ok
RUN
Value of X = 20
Value of Y = 10
Addition of X and Y = 30
Ok    
        
              
 
    

Sunday, May 19

End Statement

The END statement terminates program execution , closes all files and returns to the command level.
Syntax
END

  • Generally, the END statement indicates the end of a BASIC program.
  • END statement may be placed any where in the program to terminate execution.
  • END closes all files.
  • GW - BASIC always returns to the command level after END is executed.
Example 2

      .            .
      .            .
      .            .
100 End
It ends the program and returns to the command level.
Ok
LIST  
10   REM Learning use of END statement
20   REM Values of two numbers X and Y
30   X = 20
40   Y = 10
50   REM Addition of two numbers X and Y
60   A = X+Y
70  END
Ok
RUN
Ok


Diplay on the screen for END statement

Ok
LIST
10  REM Learning the use of END statement
20  REM Values of Base and Height of a triangle
30  B = 2
40  H = 4
50  REM Area of the triangle
60  A = 1/2*B*H 
70  END
Ok
RUN
Ok    
      

Tuesday, May 7

BASIC Statements

Program comments - the REM Statement 
The REM statement allows remarks to be inserted in program.
Syntax
LN REM  [comment]
'                 [comment]
Where, 
LN : Line Number
Comment : Remarks written by the programmer
'                : Apostrophe (') may be used in place of REM.
Points to Remember :

  •  REM statements are not executed, but they are listed with all other.
  • Statements in BASIC program.
  • Once REM or ' (apostrophe) is encountered, the program ignores everything until the next line number is encountered.
  • REM Statement may be branched into from GOTO or GOSUB statement.
  • Remarks can be added to the end of a line by an apostrophe (') instead of REM.
Example 1

1. 10 REM This program calculates percentage.
2. 20 REM Program to find area of a triangle
3. 30 REM " My Test Result"
4. 40 REM A = x + y 'Addition of x and y
Use of REM statement and apostrophe (') in the program. Suppose we have two numbers.
x = 20
y = 10
Now, we will write a program to add  these two numbers. The remarks are written using REM statement and apostrophe (')

CS 4.1 Display on the screen for REM statement

Ok
LIST 
10  REM Learning the use of REM statement
20  REM Values of two numbers x and y
30  X = 20
40  Y = 10
50  REM Addition of two numbers x and y
60  A = X+Y
Ok
RUN
Ok


CS 4.2 Display on the screen for REM statement

Ok 
LIST 
10 REM Learning the use of REM and apostrophe (') statement
20 REM Values of two numbers X and Y
30 X =20 'VALUE OF X
40 Y = 10 ' VALUE OF Y
50 REM Addition of two numbers X and Y
60 A=X+Y 'Addition of X and Y
Ok
RUN
Ok          

  

Sunday, May 5

RM DIR Command

The RMDIR Command is used to delete a sub directory.
Syntax
RMDIR pathname
Where,
Path name : Location of sub directory to be removed (deleted)
  • The path name must not exceed 63 characters.
  • The sub directory is to be removed from its present directory
  • The sub directory to be deleted must be empty (i.e. with no files)
Example 27

1. RMDIR CLASS IX (press enter key)
It is used to delete sub directory CLASS IX from its parent directory (current directory).
2. RMDIR "A : \ GWBASIC" (press enter key)
It is used to delete GWBASIC sub directory