A variable is a storage location paired with an associated symbolic name called identifier.

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

AString$ = "Hello World"
Anumber% = 10

Print AString$
Print Anumber%

A variable identifier consists in a valid identifier optionally followed by the
  • string-type declaration character $,
  • integer-type declaration character %,
  • byte-array-type declaration character @,
  • double-precision floating-point character !,
  • boolean-type declaration character #,
  • 64 bit integer-type declaration character &
In case where type declaration character is not specified, floating point type will be assumed.
nuBASIC enables both the creation of a variable through simple assignment without an explicit declaration statement and the declaration of a variable specifying its name and characteristics using Dim Statement 

A variable exists from the moment that you assign it a value in your code or declare it by using Dim.

A =  -123.5 : Rem Floating-point
A! = 1E50 : Rem Double floating-point
A% = &HFF0000 : Rem Integer 32 bit
A$ = ”This is a string” : Rem String
A# = false : Rem Boolean

Dim i as Integer   : Rem i is just an integer
Dim s(2) as String : Rem s is an array of two strings

Explicit type declaration syntax:

  • Dim var as String: string-type declaration 
  • Dim var as Integer: nteger-type declaration 
  • Dim var as Double: double-precision floating-point 
  • Dim var as Boolean: boolean-type
  • Dim var as Long64: 64 bit integer-type declaration

Type deduction

Type deduction is possible by using the keyword Any.
For example:

Dim x as Any ' x can become any type at run-time
x = "string" ' x becomes a string (it cannot change anymore)


If you want to prevent unwanted modifications to variables that for some reason should not be changed, you have to declare them "const".
Const keyword allows to assigns the value of an expression to a constant variable. Constant variables are non‐modifiable.


Const square2 = 1.41

Subpages (2): Arrays Structures