Variables in Qbasic
Variable
A variable is a name of storage location in the computer’s memory, we can store different values in a Qbasic variables. A variable is needed in the program to store different data in the computer memory which are used for processing. The value stored in the variable is not fixed as its value may change during program execution time.
Rules for naming a variables in Qbasic
- A variable beginning should be with alphabets like : a, b, c, or A,B, C
- We can’t use keyword as a variable
- We should declare variable with a valid name means a unique name should be given to a variable.
- Variable name must be only up to 40 characters long in QBASIC.
- We can only use characters like: #,&,$,% and ! for declaring variable.
- Variables names are not case sensitive
Some valid or invalid Variables
Variable Name | Valid | Invalid | Reason |
Roll.No | Valid | Variable name can have period | |
First_Name$ | Valid | Variable name can have underscore | |
FisfName$ | Valid | Variable name can have pascal case and camel case | |
12abc | Invalid | Variable name must start with alphabet | |
Kathmandu Nepal$ | Invalid | Variable name cannot have space | |
Fname$ | Invalid | Started with fn alphabets | |
RUN | Invalid | RUN is reserved word |
There are Two types of variable
- String Variable
- Numeric Variable
String Variable
A variable which stores alphanumeric data is known as string variable it occupies 4 bytes for description and one byte for each character for string data.
Example: Name$, School$ address$ etc.
CLS
PRINT "Welcome to Hi Tech Computer"
name$ = "Yam Soti"
ADDRESS$ = "Tulispur-5, Dang"
PRINT name$
PRINT ADDRESS$
END
Numerical Variable
A variable which stores only number (numeric data) is called numeric variable. Numeric data means that can perform mathematical calculations.
Types of Numeric Variable
- Integer
- Long Integer
- Single Precision
- Double Precision
1. Integer Variable
The integer variable stores a whole numbers without decimals. Integer may range from -32768 to 32767. It occupies 2 byte of memory to store an integer. Ex. X% = 15, RollNumber%, Age% etc.
CLS
a% = 12
b% = 10
sum = a%+b%
Print sum
End
2. Long Integer Variable
The long integer variable can store a large range of whole number without decimals. It stores long integer ranges from -2147483648 to 2147483647. It occupies 4 byte in memory to store long integer. Ex. acNumber&, registrationNumber& etc.
CLS
a& = 12345789
b& = 10542
sum = a&+b&
Print sum
End
3. Single Precision Variable
Single precision variable stores whole number with decimal point. It stores up to 7 digits number. It occupies 4 byte in memory to store numeric data. Ex. BasicSalary!, price!, tax! Etc.
Example:
CLS
salary! = 9500.50
bonus! = 1296.81
sum = salary! + bonus!
Print sum
End
4. Double Precision Variable
Double precision variable also stores whole number as well as number decimal point. It stores number having up to 16 digits. It occupies 8 byte in memory to store number. Ex. lightSpeed#, distanceMoon# etc.
Example:
CLS
abc# =123456789.50
D# = 123456789D+10
Print abc#
Print D#
End
You made some decent points there. I checked on the web to find out more about the issue and found most individuals will go along with your views on this web site. Inger Derry Weiser
Your style is very unique in comparison to other people I have read stuff from. I appreciate you for posting when you ave got the opportunity, Guess I all just book mark this web site. Maressa Llywellyn Stanford
Thanks for the tips you have provided here. Cheers! Mara Coop Alo
Dear Barbara, you are most graciously welcome! Blessings dear friend. I hope and pray you are safe and well. Regina Geno Bernhard
Great delivery. Great arguments. Keep up the good work. Nikki Jared Magbie
Kapan keluar ini bos,, mau cobain cobain main bos,, Emelda Gavan Bendick
Way cool! Some very valid points! I appreciate you penning this post and also the rest of the website is extremely good. Roselia Alessandro Neddy Fancy Marlo Angus
There are a few checklist items that should be in each comment. Cristal Nicholas Carolynne
My brother recommended I might like this web site. Loren Galvan Goodyear
Thank you for the recipe Ann. This sounds amazing. I sent your link to my sister who loves Indian food and she is excited to try it. Jobye Hayward Seligman
I have been absent for some time, but now I remember why I used to love this website. Thank you, I will try and check back more frequently. How frequently you update your site? Charla Arlan Schoenfelder