ArcBasicDocs

Basic Data Types

Every value in ArcBasic is one of three basic kinds, or an object of a type of your own.

Integers

Whole numbers, such as 0, 42 or -7. They are the default: a variable without a type tag holds an integer. ArcBasic's integers are 64-bit, so they go from about minus 9 million million million to plus 9 million million million (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807), plenty for scores, counters and timers.

Integers can also be written in hexadecimal with a $ in front, as in $FF (255), or in binary with a % in front, as in %1010 (10). Both are handy for colours and bit flags.

Floats

Decimal numbers, such as 3.14, -0.5 or .25. A number with a decimal point is a float; so is a whole number with # after it, as in 5#. Very big or small numbers can be written with an exponent after a decimal point: 1.5e3 is 1500 and 2.0e-3 is 0.002.

ArcBasic's floats are 64-bit (double precision), accurate to about 15 significant digits. When printed or turned into text, they show up to six significant digits, and always with a decimal point: Print 1.0 / 3 shows 0.333333 and Print 7.0 shows 7.0. Like decimals on any computer, most fractions are stored very slightly off, so check whether a float is close to a value rather than exactly equal to it.

Strings

Text, written between double quotes: "Hello". An empty string is "". A string must end on the line it starts on, and there is no way to type a double quote inside one; use Chr(34) for it, as in Print "Say " + Chr(34) + "hi" + Chr(34). Join strings with +; the string commands, such as Left, Mid, Len and Instr, take them apart.

Converting between them

ArcBasic converts between the kinds wherever it needs to:

  • A float put into an integer variable is rounded to the nearest whole number: n = 2.7 makes n 3.
  • An integer put into a float variable becomes the same number with a fraction of 0.
  • A number joined to a string with + is turned into text: "Score: " + score.
  • Text put into a number variable is read as a number for as far as it looks like one: n = "12 apples" makes n 12, and text that doesn't start with a number gives 0.

To convert on purpose, use Int, Float and Str. Float matters most: dividing two integers gives an integer, so 7 / 2 is 3, but Float(7) / 2 is 3.5.