Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Data Types in QBasic: String.........Text and characters Example of a String Data Type: This line is an example of a string Integer.......

Non-floating-point numbers from -32,768 to 32,767 Examples of an Integer Data Type: 67, -34, -100, 203, 1022, -1, 0 Long..........Non-floating-point 2,147,483,647 numbers from -2,147,483,648 to

Examples of a Long Data Type: 560005, 3, -2, 0, -867000, 14, 8, -10 Single........Floating-point numbers from -3.37x10^38 to 3.37x10^38 Examples of a Single Data Type: 4.3, 25.4567, -35.87, 0.35, -3.14 Double......Floating-point numbers from -1.67x10^308 to 1.67x10^308 Examples of a 4859903.094491 Double Data Type: 745663.90596, -98.12,

It is possible to make your own data type, but we are not going to cover how to do that until later in this tutorial series. Variables Variables are a name that is given to the data. The name must not start with a number or character that is not a letter. Also, the name of the variable must not be a reserved name like PRINT, INPUT, LET, ABS, BEEP, etc. There are two ways to declare a variable in QBasic The first is to put a data type symbol after the name $ String % Integer & Long ! Single # Double

The flowing program gives and example of declaring variables. CLS Header$ = This is an example program on declaring variables Num1% = 5 Num2% = 6 Num3& = 45000 Num4& = 54000 Num5! = 4.5 Num6! = 6.76 Num7# = 56000.25 Num8# = 89000.34 PRINT Header$ PRINT Num1% + Num2% +Num3& PRINT Num6! / Num5! PRINT Num8# + Num2% PRINT Num4& / Num1% The output will be:

This is an example on declaring variables 45011 1.502222 89006.34 10800 Lets try the other way of declaring variables. This method should be used instead of the other method because Visual Basic and other BASIC languages tend to use this method. Becoming accustom to this way will help the transition from QBasic to Visual Basic. Create a new file and try this out: 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 program on declaring variables Num1 = 5 Num2 = 56000

Num3 = 45.635 Num4 = 66000.5634 PRINT Header PRINT Num1 + Num2 + Num3 + Num4

You might also like