Language Reference
Documentation

Language

Objects
Internet Objects

Data Types and Variables

Data Types

The language defines three intrinsic (primitive) data types. These data types are string, integer and float. All literal values are of one of these types.

A literal value is one that you write as it is in the source code. For example the value 100 or the word "Jose".

Strings
A literal string values is a group of characters, a word or a series of words. A literal string value is always written inside double quotes. The bellow representations are all valid string literals:

"Jose L. Cuevas"    "HELLO WORLD"     "^%&$^%#%$HGVFC"

String literals also support escape sequences like "\n". An escape sequence allows you to change the meaning of a character in a string. An escape sequence starts with the character "\" followed by a single character. When an escape sequence is found inside a string literal it is replaced by its meaning.
Here is a list of escape sequences supported by BAXIC:

\n inserts a new line character. In Mac is ASCII 13 in Windows is ASCII 13 and ASCII 10.
\t  inserts a tab (eight spaces).
\r inserts ASCII 10.
\f inserts ASCII 13.
\" inserts a double quote inside a string.

Escape sequences allows to do things like:
   "Hey \"This is cool\"!!!!"
Notice that a string literal starts and ends with a double quote, without the escape sequence the above string literal would generate an error since is not valid. The above string literal becomes:
   Hey "This is cool"!!!!   

For the rest of the documentation any string literal will be called a STRING.

Numbers
In source code you can write numeric literals. A numeric literal may be any numbers, it may start with a negative symbol. Decimal portions must be prefixed with a zero if no whole part is included. For example:

23        1.07        -5         14567      0.5 0.3e+10

A number without a decimal portion is known in BS as an INTEGER. A number with a decimal portion is a FLOAT.

INTEGER:

An integer is a whole number. Its range is from +- 2,147,438,648. Use the math library function cint to cast a value to an integer. An integer in BS is considered a LONG in other languages.

FLOAT:

A FLOAT is a number that may contain a decimal part. Its range is from 2.2250738585072013 e-308 and 1.7976931348623157 e+308. Use the math library function cfloat to cast a value to a float. A float is also known as a double precision real number.

Currently BAXIC provides little support for very large floating point/real numbers, yet current support should be enough for most calculations. We hope that in a future support is added for advanced scientific and methematical calculations.

User Defined Data Types

A User Defined Data Type or UDT is like a special data type that the user defines. Sometimes the basic data types are not enough or do not allow for an easy representation of certain data or relationship among the data. For example if you wanted to represent an employee in code you could use string variables like "Name", "Title", or a numeric variable like "Salary". Yet all of these variables have something in common an that is that they represent an employee. They have a common relationship. Not only that but a variable salary may apply for something else in your code, therefore you may want to know that this is the salary of an employee not some other salary. For this particular example it would be great if we could define a variable of type "employee" that had properties like "name", "salary" and others.

BAXIC allows you to define two types of UDTs, Structures and Classes. The structure is the most basic of the two.

Structures
The structure also known as a Type Structure allows you to group a series of variables under another variable. We define a type structure as follows:

Type Car
     Brand as string
     Model as string
     Year as integer
End Type

We use the keyword "TYPE" to indicate that we want to define a type structure. The keyword Type is followed by the name of our new data type. Inside our type block we define the properties or variables that made up our new data type. We finally close the type structure with the keywords "END TYPE".

In the above example we have defined a new data type named Car. This data type has the properties Brand, Model and Year. Now we can declare a variable of type Car as follows:

            DIM MyCar as Car

With this new variable of type Car now we can said things like:

            MyCar.Model = "XTerra"
            MyCar.Year = 2004

In the above examples you may have notice that we use the dot (period) to access a property of our type structure. Notice also that the name of the properties are that same as the ones we used to define our structure.

Classes
A class just like a type structures allows you to group properties with a particular relationship under one data type. Classes have one advantage over structures and it is that they let you associate code that you may execute along with your properties. In the example above lets said we add the property "EngineModel" to the structure. If you want to change the "EngineModel" you have to call a function or add the code to change the variable. Notice this code would be somewhere in your program and you must duplicate the code every time you want to do the same. With an class I can put the code together with my new data type. Lets see how we declare a class:

Class Car
     Public Property Brand as string
     Public Property Model as string
     Public Property Year as integer
     Public Property EngineModel as string

     Public Sub ChangeEngineModelToBasic( )
                me.EngineModel = "Basic"
     End Sub

End Class

Variables

Variables like in any other programming language allow you to store and represent a value (a data type). A variable can store one value of a given data type. The data type of a variable determines what type of data the variable can store.

A variable can be of type STRING, INTEGER, FLOAT or any other data type supported by the language.

Variables are represented by a name. Each variable must have a unique name in a given scope. The name of variables must start with an alphabetic character and may NOT contain spaces or punctuation symbols other than the underscore. The name of a variable may not be equal to a reserved keyword or the name of an object or used defined structure or class.

To declare a variable use the DIM statement. You have to declare a variable before you use it. The syntax of the DIM statements is DIM variablename as datatype.