How to get input from the user at the run time?
Interacting with the user, collecting and processing the real-time
data is an important task of a software. So, how do we get the input from the
user.
INPUT – keyword should be used in BASIC to get the data.
How can I implement that in program?
1 PROGRAM GET.INPUT.FROM.USER
2 CRT “Enter your Name: ”
3 INPUT NAME
4 CRT “Hi ”:NAME
5 RETURN
6 END
The above code will print the below,
Enter your Name:
Anbu
Hi Anbu
“:” - Is the concatenation operator. At line 4, the
string Hi is concatenated with the value in NAME variable.
OK. All the data can be processed with in a single session
and how do I handle data across two or more session.
Creating a COMMON container:
Create a COMMON container, that will hold all the variables
shared across the session. Let’s create a COMMON container.
What is the syntax:
COMMON//,
Example:
//COMMON1
PROGRAM COMMON1
COMMON/COMMON.CONT1/C, E
A=2; B=1; C=3
Z=A+B ;* value of Z is 3
C = A+C ;*value of C is 5
CALL COMMON2
CRT E ;* 5 will be printed.
RETURN
END
//COMMON2
SUBROUTINE COMMON2
COMMON/COMMON.CONT1/C, E
CRT C ;* 3 will be printed
CRT A ;* nothing will be printed
E=5;
RETURN
END
The above program clearly explains the data handling across
sessions. The variables in the common container can only be accessed across
session.
Do I need to use the common container in both routines? Yes,
the exact same container should be used in two programs. It is the anatomy of
BASIC.
How can I write a common container only once, without impacting
the behavior?
Write the common container in a new file lets name it as
I_COMM.VARI
//I_ COMM.VARI
COMMON/COMMON.CONT1/C, E
//COMMON1
PROGRAM COMMON1
$INSERT I_COMM.VARI
A=2; B=1; C=3
Z=A+B ;* value of Z is 3
C = A+C ;*value of C is 5
CALL COMMON2
CRT E ;* 5 will be printed.
RETURN
END
//COMMON2
SUBROUTINE COMMON2
$INSERT I_COMM.VARI
CRT C ;* 3 will be printed
CRT A ;* nothing will be printed
E=5;
RETURN
END
$INSERT - will include the file in that routine. This
will be much useful, when there are many variables (about 50) in the common
container.
Do you have better implementations, please let us know in
the comments below?
Comments
Post a Comment