Download QBasic_Learn

Transcript
www.omideiran.net
www.ircdvd.com
www.irebooks.com
www. irtanin.com
The integer type handles numbers without decimals. Integers may range from -32768 to 32767. Math with
integers may be faster than math with single-precision variables. For programs that have to run very fast,
using integers might be useful. In a DIM statement, use "INTEGER" to create an integer variable. The typecharacter for an integer variable is "%". Here are some examples of creating and using integer variables:
X% = 32
DIM Y AS INTEGER
Y = 55
PRINT X%; Y
Since math with integers is very fast, you will commonly see the following line near the beginning of
QBASIC programs:
DEFINT A-Z
This tells QBASIC to stop assuming that every variable is single-precision, and instead to assume that all
variables are integers. This way you don't need to use DIM or the "%" symbol throughout your program to
make all your variables integers.
Long-Integer
The long-integer type handles numbers without decimals. Long-integers may range from -2147483648 to
2147483647. Math with long-integers is usually almost as fast as math with integers. For programs that have
to run very fast, using long-integers might be useful. In a DIM statement, use "LONG" to create a longinteger variable. The type-character for a long-integer variable is "&". Here are some examples of creating
and using long-integer variables:
X& = 65536
DIM Y AS LONG
Y = 121072
PRINT X&; Y
Double-Precision
The double-precision type handles numbers with decimals. You can go up to fifteen digits with a doubleprecision variable. Double-precision variables are used where very accurate math is needed. In a DIM
statement, use "DOUBLE" to create a double-precision variable. The type-character for a double-precision
variable is "#". Here are some examples of creating and using double-precision variables:
X# = 3.14159265358979
DIM Y AS DOUBLE
Y = 1.23456789012345
PRINT X#; Y
Arrays
An array lets you store a list of things. Arrays are very similar to variables, but they hold more than one
thing. Try this:
N$(0)
N$(1)
N$(2)
N$(3)
=
=
=
=
"Ted"
"Jack"
"Jill"
"Fred"
$*