Variable Types
Sesame will convert any value you assign to a variable to the type you said you wanted in the declaration. Because of this, it is important you use the correct type for your variables. If you do not include the variable type in the declaration, the type will default to Int (integer). This can cause unpredictable results if you are expecting to sue the variable for text or number with decimal places. Always include the type in the declaration.
The available types are as follows:
-
String: Any text. If in doubt, use this type.
var vMyVar as String vMyVar = "John Smith" vMyVar = "Blue;Green;Red" vMyVar = Last Name
-
Int: An integer (whole number). Integers do not store decimal places.
var vMyVar as Int vMyVar = 10 vMyVar = InvoiceNumber
-
Double: A floating point number
var vMyVar as Double vMyVar = 1.72568 vMyVar = AverageDistance
-
Money: A fixed point number. This type is fixed at 4 decimal places and will be the most relaiable for money calculations.
var vMyVar as Money vMyVar = 13.25 vMyVar = InvoiceTotal
-
Date: A date. SBasic dates are different from dates stored in a Sesame database. Date fields are stored as strings in the format YYYY/MM/DD. You can grab pieces of them using @Left() and other such functions. SBasic dates do not work this way. If you need to use string functions on your date field value, assign it to a variable of type String instead of type Date.
var vMyVar as Date vMyVar = "Jan 1, 2005" vMyVar = @Date
-
Time: A time. SBasic times are different from times stored in a Sesame database. Time fields are stored as strings in the format HH:MM:SS. You can grab pieces of them using @Left() and other such functions. SBasic times do not work this way. If you need to use string functions on your time field value, assign it to a variable of type String instead of type Time.
var vMyVar as Time vMyVar = "2:35" vMyVar = @Time
-
Boolean: A Boolean value can only have two possible values, True or False. These will also recognize Yes/No, 1/0, On/Off, etc. This type is good for setting and checking failure conditions.
var vMyVar as Boolean vMyVar = True vMyVar = 1 vMyVar = "Yes"
-
Char: A single character. This type is rarely used. Use String instead.
Var vMyVar as Char vMyVar = "A"
- Intptr: An integer the same size as a pointer (memory address) for your system, either 64 bits or 32. In can only be used for @GenerateMemoryAddress, @AllocateMemoryFromAddress, @rp(), wp(), increment by int/intptr, and decrement by int/intptr. Increment and decrement results in an intptr - not an int.
- The new SBasic operator "&" is used to derive the memory address of a variable into a intptr variable:
Var addr as intptr Var bb as int Addr = &bb
Note: this is dangerous and should only be used when a variable needs to be altered/used in binary, usually when using and external shared library.
- The new SBasic operator "*"Â is used to derive the value at a memory address into a variable:
Var addr as intptr Var bb as string Var cc as char bb = "whatever" addr = &bb cc = *&bb
Note: The *& operator will "return" a CHAR (BYTE), unless it is used as the right side of an assignment operator, in which case it returns the type of the left side of the converted to the type for that argument. Like the negation operator ("-", i.e.: - VarName), this operator cannot appear as the left side of a truth expression (like an "if()").
- The new SBasic operator "=" is used to write a memeory address that an intptr variable "points" at:
Var addr as intptr Var bb as string Var cc as char // Turns "Mom" into "Tom" Bb = "Mom" Cc + "T" Addr + &bb bb &= cc
Notes: this is dangerous and should only be used when a variable needs to be altered/used in binary, usually when using an external shared library.