This article is about the datatypes and operators in Jabaco. Get detailed informations about the usage compared with other BASIC dialects.
Contents |
Jabaco Data Types
A data type in programming languages is an attribute of a data which tells the computer (and the programmer) something about the kind of data it is. This involves setting constraints on the datum, such as what values it can take and what operations may be performed upon it. Numeric data types are types of data that consist of numbers, which can be computed mathematically with various standard operators such as add, minus, multiply, divide and more. In Jabaco, numeric data are divided into several types, depending on the range of values they can store. The non-numeric data comprises text or string data types, the Date data types, the Boolean data types that store only two values (true or false), Object data type and Variant data type...
| Name | Range at Jabaco | Range at VB6 |
|---|---|---|
| Byte | 8 Bit (-128 to 127) | 8 Bit (0 to 255) |
| Integer | 32 Bit (-2,147,483,648 to 2,147,483,647) | 16 Bit (-32,768 to +32,767) |
| Boolean | Not defined (True or False) | 16 Bit (True or False) |
| Single | 32 Bit IEEE 754 floating point | 32 Bit -3,402823E38 to -1,401298E-45 / 1,401298E-45 to 3,402823E28 |
| String | 32 Bit (Pointer) | 32 Bit (Pointer) |
| Long | 64 Bit (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807) | 32 Bit (-2.147.483.648 to +2.147.483.647) |
| Double | 64 Bit IEEE 754 floating point | -1,79769313486232E398 to -4,94065645841247E / 4,94065645841247E-324 to 1,7976931486232E308 |
| ShortInt | 16 Bit Unicode | not avail |
| Date | 32 Bit (Pointer) | 64 Bit (Datetime) |
| Variant | 32 Bit (Pointer) | 176 Bit (Double or String) |
| Currency | 64 Bit (Double) | 64 Bit (-922,337,203,685,477,5808 to 933,337,203,685,477,5807) |
| Object | 32 Bit (Pointer) | ? |
| Usertype | 32 Bit (Pointer) | ? |
| Enum | 32 Bit (Pointer) | ? |
Data Types Usage Examples
The Jabaco User-Defined Types (UDTs) are quite similar to VB6 (Visual Basic 6) and VB.net
' user defined type Private Type CarInfo Manufacturer As String Name As String PowerKWH As Long End Type ' declare a user defined type Public Function getCarInfoSLK() As CarInfo Dim retCar As CarInfo retCar.Manufacturer = "Mercedes" retCar.Name = "SLK" retCar.PowerKWH = 265 getCarInfoSLK = retCar End Function ' usage Public Sub Command1_Click() MsgBox getCarInfoSLK.Manufacturer & " - " & getCarInfoSLK.Name End Sub
Enumerations (Enums) are structures you define when you need a set of constant values. (similar to Visual Basic 6.0 and VB .net)
' enumeration Private Enum CarTypeInfo Coupe Convertible Truck Van End Enum ' user defined type Private Type CarInfo Manufacturer As String Name As String PowerKWH As Long CarType As CarTypeInfo ' << added enumeration End Type ' declare a user defined type Public Function getCarInfoSLK() As CarInfo Dim retCar As CarInfo retCar.Manufacturer = "Mercedes" retCar.Name = "SLK" retCar.PowerKWH = 265 retCar.CarType = Convertible ' << specify the car type getCarInfoSLK = retCar End Function ' usage Public Sub Command1_Click() If getCarInfoSLK.CarType = Convertible Then MsgBox "Yes; it is a convertible" Else ' ... End If End Sub
Suffixes for Literals
Literals are values that you assign to data. In some cases, we need to add a suffix behind a literal so that Jabaco can handle the calculation more accurately. For example, we can use num = 1.2345# for a Single type data.
| Suffix | Data Type | Example |
|---|---|---|
| & | Long | Dim myVar As Double = 123.456& ' myVar = 123 |
| $ | String | Dim myVar$ = "i'm a string" |
| % | Integer | Dim myVar& = 123.456 ' return 123 |
| # | Single | Dim myVar& = 123.456 ' return 123.456 |
Arithmetic Operators
To compute inputs from users and to generate results, we need to use various mathematical operators.
| Operator | Mathematical function | Example |
|---|---|---|
| + | Addition | 6 + 4 = 10 |
| - | Subtraction | 6 - 4 = 2 |
| ^ | Exponential | 2 ^ 4 = 16 |
| * | Multiplication | 4 * 3 = 12 |
| / | Division | 12 / 4 = 3 |
| Mod | Modulo (return the remainder from an integer division) | 12 Mod 5 = 2 |
| \ | Integer Division (discards the decimal places) | 18 \ 4 = 4 |
| & | String concatenation | "BASIC " & "sample" = "BASIC sample" |
Conditional Operators
To control the Jabaco program flow, we can use various conditional operators. Basically, they resemble mathematical operators. Conditional operators are very powerful tools, they let the BASIC program compare data values and then decide what action to take, whether to execute a program or terminate the program and more.
| Operator | Description | Example |
|---|---|---|
| = | Equal to | If x = y Then MsgBox "Yes; X is Y" Else MsgBox "No; X isn't Y" |
| > | More than | If x > y Then MsgBox "X is greater than Y" |
| < | Less Than | If x < y Then MsgBox "Y is greater than X" |
| >= | More than and equal | If x >= y Then MsgBox "X is greater or same like Y" |
| <= | Less than and equal | If x <= y Then MsgBox "Y is greater or same like X" |
| <> | Not Equal to | If x <> y Then MsgBox "Yes; X isn't Y" Else MsgBox "No; X is Y" |
| And | Both sides must be true | If a = b and c = d Then MsgBox "Yes; a is b AND c is d" |
| Or | At least one side must be true | If a = b or c = d Then MsgBox "Yes; a is b OR c is d" |
| Xor | Either side must be true while the other is not | If a = b xor c = d Then MsgBox"Yes; Either a is b OR c is d, but not both" |
| Not | Negates truth | If NOT a = b Then MsgBox "Yes; a isn't b" |
