What are variables

A variable is a convenient placeholder that refers to a location in the computer memory where you can store program information that may change during the time your script is running. For example, you might create a variable called Count to store the number of files present in a directory. Where the variable is stored in computer memory is unimportant. What's important is that you only have to refer to a variable by name to see its value or to change it.

Variable Types

thinBasic supports 4 main variable types:
  • numeric
  • string
  • user defined types
  • variant

For each of them there are many numeric and string subtypes.

Numeric variables serve for storage of numbers. Numeric types are divided into two main subtypes:

  • integer - to hold integer numbers (whole numbers)
  • floating point - to hold both integer and floating point numbers (decimal numbers)
If you don't care about performance, you can simply use the variable type called NUMBER. But for more complex tasks you might pick variable types more carefully. You can refer to the ThinBASIC help file for more detail on memory occupancy, ranges and precision of the numeric variable types.

String variables serve for storage of text. Strings are divided into two big categories:

  • fixed length
  • dynamic (able to change in size)
Fixed length strings in ThinBASIC are represented as ASCIIZ and STRING * n. They have a predetermined maximum size. This is good for performance, yet it might be unsuitable for tasks where you don't know how much text there will be. Dynamic strings, named simply STRING, are for more general purposes. Their size can dynamically grow and shrink.

User defined types (UDTs) come in the game when you need to group a logical set of variables together. A typical use for them is the representation of a three dementional vector, which is represented by 3 numbers - x, y and z. Unlike many other languages, ThinBASIC supports dynamic strings inside UDTs.

The variant data type is a specific general purpose variable, which can hold both numeric and string data with a slight performance hit.