the two types of variables in small basic
Answers
numeric and string variable is the answer
There are a bunch of SmallBasic enthusiasts lined up for blogging here, so you can expect more regular blog posts on all sorts of varied SmallBasic related stuff.
So here's some thoughts on the Small Basic variables...
Small Basic has only one variable type. A variable is something that stores data that can change as the program runs. A type is the kind of data that is stored in the variable.
For example, a variable may be a number or some text. A number is either an integer or a decimal (with a fractions after a decimal point). Text is usually called a string.
A variable may also be an array collection of data or some graphical object like a TextBox or Ellipse shape.
In most languages data of different types are stored in variables of a specific type that can only hold that kind of data. So an integer type variable can only store integers and a string type can only store text.
In SmallBasic all data are stored in a single variable type called Primitive. This data type can be converted between integers and decimals, strings and arrays as the context changes.
This means that any variable is actually stored as a Primitive string (just a set of characters) and the Primitive checked as follows:
1] is it an array? If so then it is an array of Primitives
2] is it a number (integer or decimal both treated as a decimal)?
3] if none of the above it is a string
Depending on if the variable can be converted to a number or not it will be treated as a number or text string.
So the following behaves like adding numbers:
TextWindow.WriteLine("3"+"4") behaves likeTextWindow.WriteLine(3+4) orTextWindow.WriteLine(3+"4")
and these behave like strings since "3a" or ":" cannot be converted to numbers.
TextWindow.WriteLine("3a"+"4") orTextWindow.WriteLine(3+":"+4)
We can see the Primitive string format for arrays by writing them to the TextWindow:
a[1] = "hello"
TextWindow.WriteLine(a)
above shows that a is actually "1=hello;" which is the Primitive format that shows that a is an array.
All graphical objects are stored as character strings, so:
ellipse = Shapes.AddEllipse(20,20)
TextWindow.WriteLine(ellipse)
Above shows that ellipse is labelled "Ellipse1" and this is used to identify the ellipse when it is moved for example with:
Shapes.Move(ellipse,50,50)
We could get the same effect with:
Shapes.Move("Ellipse1",50,50)
or even:
Shapes.Move("Ellipse"+1,50,50)
When you move past SmallBasic you will be confronted with getting your types right and creating your own types, but SmallBasic looks after it all for you!