411 REFERENCE · Wikibooks
BASIC Programming/Beginning BASIC/Variables and Data Types
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Variables allow you to store and change information. Below is an example how to use variables.
Example Code for Variables
Example 1 (qBasic)
CLS
ASTRING$ = "Hello World"
ANUMBER% = 10
PRINT ASTRING$
PRINT ANUMBER%
Example 1.2 (freeBasic)
Cls
Dim aString As String
Dim anInteger As Integer
aString = "John Doe"
anInteger = 42
Print aString
Print anInteger
Sleep
End
Output
Example 1
Hello World
10
In Basic, a string variable ends in a $, and whole number variables, known as integers, end with a %.
Example 2
John Doe
42
If you use Dim varName As DataType to declare variables, you do not need to use a suffix.
Arrays
An array is a collection of values.
Cls
Dim aNames(3) as String
aNames(1)="John Doe"
aNames(2)="Jane Doe"
PRINT aNames(1)
PRINT aNames(2)