Variables in Qbasic

  Blog Desk       September 24, 2019     5369 12 Comments
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

  1. A variable beginning should be with alphabets like : a, b, c, or A,B, C
  2. We can’t use keyword as a variable
  3. We should declare variable with a valid name means a unique name should be given to a variable.
  4. Variable name must be only up to 40 characters long in QBASIC.
  5. We can only use characters like: #,&,$,% and ! for declaring variable.
  6. Variables names are not case sensitive

Some valid or invalid Variables

Variable NameValidInvalidReason
Roll.NoValidVariable name can have period
First_Name$ValidVariable name can have underscore
FisfName$ValidVariable name can have pascal case and camel case
12abcInvalidVariable name must start with alphabet
Kathmandu Nepal$InvalidVariable name cannot have space
Fname$InvalidStarted with fn alphabets
RUNInvalidRUN is reserved word

There are Two types of variable

  1. String Variable
  2. Numeric Variable
Variables in Qbasic

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

  1. Integer
  2. Long Integer
  3. Single Precision
  4. 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

Symbolic Constants in QBASIC

12 responses to “Variables in Qbasic”

  1. canli says:

    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

  2. haber says:

    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

  3. dizi izle says:

    Thanks for the tips you have provided here. Cheers! Mara Coop Alo

  4. dizi says:

    Dear Barbara, you are most graciously welcome! Blessings dear friend. I hope and pray you are safe and well. Regina Geno Bernhard

  5. erotik says:

    Great delivery. Great arguments. Keep up the good work. Nikki Jared Magbie

  6. canli tv says:

    Kapan keluar ini bos,, mau cobain cobain main bos,, Emelda Gavan Bendick

  7. movie online says:

    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

  8. episodes says:

    There are a few checklist items that should be in each comment. Cristal Nicholas Carolynne

  9. yetiskin says:

    My brother recommended I might like this web site. Loren Galvan Goodyear

  10. 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

  11. yetiskin says:

    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

  12. diziler says:

    Somebody essentially lend a hand to make seriously posts I would state. This is the first time I frequented your web page and up to now? I surprised with the research you made to create this particular post incredible. Fantastic activity! Hyacinthie Beauregard Lisandra

Leave a Reply

Your email address will not be published. Required fields are marked *