Variables #1: Introduction

Variables are entities which you can use to store, update and read value.

ThinBASIC is a strongly typed language. You are in control over the variable data type. There are basically two kinds of data types – for numbers and for text.

Numeric data types

There are multiple data types for numbers, to give you choice of the most appropriate solution for your task. They further split to integer and floating point types. The first group is suitable for whole numbers, the second one for numbers which have fractional part.

For most common tasks, long (or int32) data type is the choice for integer numbers and Double is the answer for floating point based calculations.

Further information about numeric data types, ranges of numbers they cover and the space they occupy in memory can be found in thinBasic manual.

String data types

To store text information, the strings are your area of choice. There are multiple types of string in ThinBASIC.

The most flexible is data type called simply string. Each character stored occupies 1 byte, and you can store up to 2 GB of data in single string variable. To put it in perspective, complete works of Shakespeare take about 5 MB, and string storage capacity is equivalent to 2 pickup trucks filled with books. At least according to techtarget.com.

Variable declaration

Variables need to be declared to be useful. You can assign them value during the declaration. ThinBASIC supports both the traditional form of declaration, used in most BASICs from 90’s, or the shortened variant with equivalent functionality.

The variable names must satisfy the following rules:

  • start with alphabetical character
  • can contain letters, numbers and underscore
  • their length is limited to 64
  • must be unique

Variables in expressions

Variables can be used in expressions, to perform calculations or text manipulation.

Tip for the string: When combining multiple strings together, it is faster to do so via StrFormat$ function.