Computer Science Education | Programming Language Tutorials For Beginners

QBASIC TUTORIAL 5 - Data Types in QBasics

DATA TYPES IN QBASICS
In the previous tutorial (Tutorial 4) we leant that variables can hold data in memory, the data are assigned to a data type. The data can change throughout the program’s operation, and also the data entered must be the same data type as assigned to the variables.
In this tutorial we will be learning the Data Types that are used in QBasics 1.1 and QB64, the data types are as follows:
Strings
This type of data types contains a sequence of characters (Text, Symbols etc.) which are enclosed in quotation marks.
                        “Hello World”
Integers
Integer are used to hold numbers, this data type can hold a non-floating point data types:
                       -32,768 to 32,767
Long
This data type is a non-floating data type that can hold larger numbers than the integers:
                      -2,147,483,648 to 2,147,483,648
Single
This is a floating point data type which can hold a larger numbers than the long data type:
-3.37x10^38 to 3.3x10^38
Double
This is also floating point data type which can hold a larger numbers than the single data types:
-1.67x10^308 to 1.67x10^308

N.B: Please note that QBasics 1.1 may have a problem with computations involving Double Data Types, so I will be making use of QB64 in running my programs.

In QBasics 1.1 this symbols are used in representing the data types:
$ String
% Integer
& Long
! Single
# Double

While in QB64 use:
&& Integer
## Float

Writr this codes in QBasics:

CLS

Header$ = “This is an example program”
Num1% = 5
Num2% = 6
Num3& = 45000
Num4& = 54000
Num5! = 4.5
Num6! = 6.75
Num7# = 56000.25
Num8# = 89000.34

PRINT Header$
PRINT Num1% + Num2% + Num3&
PRINT Num6! / Num5!
PRIINT Num8# + Num2%
PRINT Num4& / Num1%


After typing, run it by clicking on run or using F5 key to run it.

Output:

This is the other way of declaring variables:

DIM Num1 AS INTEGER
DIM Num2 AS LONG
DIM Num3 AS SINGLE
DIM Num4 AS DOUBLE
DIM Header AS STRING

CLS
Header = “This is another example”
Num1 = 5
Num2 = 56000
Num3 = 45.635
Num4 = 66000.5634

Print Header
Print Num1 + Num2 + Num3 + Num4

Output:
Share:

1 comment:

Popular Posts

Elitcode - Learning Start Here

Elitcode Blog Archive