BASIC Programming/Beginning BASIC/Variables and Data Types

Variables allow you to store and change information. Below is an example how to use variables.

Example Code for VariablesEdit

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

OutputEdit

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.

ArraysEdit

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)