Understanding Data Types
- Blob
- Type Symbol:
- Values:
- Character
- Type Symbol:
- Values
- Date
- Type Symbol:
- Values
- Logical
- Type Symbol:
- Values
- Numeric
- Type Symbol:
- Values
- Pointer
- Type Symbol:
- Values
- Time
- Type Symbol:
- Values
- Numeric
- Logical
- Character
- Date
- Numeric
- See
- Numeric
- See
- Logical
- Time
- See
- Assigning and Using Variables
- Choosing the Correct Data Type
- Creating Constants
- Adding comments
Description
The Xbasic programming language supports 11 types of variables (see Variable Data Types and Scope ). You will find yourself using the following types of variables.
Blob
Type Symbol:
B
Values:
Binary data (e.g. images). Blob data cannot be directly displayed. Browsers can only display image data from a named file.
Character
Type Symbol:
C
Values
Alpha-numeric characters. A NULL string is represented by "".
Date
Type Symbol:
D
Values
A date and time between where the date is between 00/00/0000 and 12/31/9999. Your browser can display date values according to your system preference.
Logical
Type Symbol:
L
Values
TRUE (.T.) or FALSE (.F.). Your browser displays these values as "True" and "False".
Numeric
Type Symbol:
N
Values
A number of up to 19 digits, or 18 digits when there is a decimal point. Your browser displays decimal numbers with 6 digits after the decimal point.
Pointer
Type Symbol:
P
Values
A reference (pointer) to an object, or a pointer to a "dot" variable. Pointers are never displayed.
Time
Type Symbol:
T
Values
A time value that stores the date, hour, minute, seconds and hundredths of a second. Your browser does not display time values.
In addition, Alpha Anywhere tables support these field types.
- Field Type
- Data Type to Use
- Image Reference
Blob
- JPEG
Blob
- Bitmap
Blob
- Memo
Character
- RTF Memo
Character
HTML displays most of the common data types without any special formatting or conversions.
Numeric
- Sample Value
- Standard HTML Display
- 12
"12"
Logical
- Sample Value
- Standard HTML Display
- .T.
"True"
Character
- Sample Value
- Standard HTML Display
- "Sam"
"Sam"
Date
- Sample Value
- Standard HTML Display
- 8/30/04
08/30/2004
Sometimes you will have to convert data types before they will display correctly on an HTML page.
Numeric
- Sample Value
- Standard HTML Display
- 1.234
"1.234000"
str(nVal,10,3,)
See
STR()
Numeric
- Sample Value
- Standard HTML Display
- $3.29
"3.290000"
str(nVal,10,2,"$")
See
STR()
Logical
- Sample Value
- Standard HTML Display
- .T.
"True"
Time
- Sample Value
- Standard HTML Display
- 2:46:04 PM
none
time("h:0m:0s AM", time_variable)
See
TIME()
Assigning and Using Variables
When you create a variable with the DIM statement you assign it one of the data types mentioned above. Afterwards, until you delete it and DIM it again, it can store only that data type. For example, if you have this statement.
dim cFirstname as C
The following statement will cause an error.
cFirstname = 3
The cFirstname field cannot store a different data type. This principle applies to all variable types. If you want to assign a value to cFirstname, you can write the first statement in two different and equivalent ways.
dim cFirstname as C = "Fred" dim cFirstname as C cFirstname = "Fred"
The practical difference is that the first alternative provides a default value for the variable, which might be useful. The numeric data type support integers and decimal numbers, sometime referred to as floating point, single, or double precision numbers in other programming languages. You do not have to worry about the placement of the decimal point. The following statements are valid.
dim nSmall as N = 2 dim nBig as N = 12000345 dim nFraction as N = -12.345 dim nVerySmall as N nVerySmall = .000000123
The date data type contains only the date. The time data type includes both date and time information. When assigning a value to a date variable, you must use curly braces and forward slashes as illustrated below.
dim dPaymentDue as D = {4/15/04} dim dAnotherPaymentDue as D dAnotherPaymentDue = {7/17/04}
When assigning a value to a time variable, you must place quotes around the values.
dim dt as T dt = "4/15/04 2:12:03 pm"
Choosing the Correct Data Type
Choosing the correct data type should be easy if you follow these rules.
Consider the character data type to be the default.
Use numeric variables to work with amounts: anything that might need to be arithmetically processed.
Use logical variables when you want a variable that can be "Yes" or "No", "On" or "Off", or "True" or "False".
Use date variables to save date values or to calculate the difference between two dates.
Use time variables to save time of day values or to calculate the difference between two time values.
Creating Constants
Constants are a special type of variable that receive a value but cannot be changed afterwards. The data type of a constant is set by the assigned value. After executing this statement,
CONSTANT TAXMONTH = 4
you can treat TAXMONTH or taxmonth as equivalent to the value 4. The value of the new_value variable below will be 12.
new_value = TAXMONTH * 3
Adding comments
Both HTML and Xbasic allow you to insert comments into a page. In both cases the comments will not appear on the page. Precede an Xbasic comment with a single quote. Remember that an Xbasic comment has to be inside an Xbasic code block, which is defined by <%a5 and %>. Surround an HTML comment with <!-- and ->. Comments are a recommended technique for documenting your applications. They make it easier to go back and maintain previously developed pages and programs.
Create a new A5W page with the following content.
<html> <head> <meta name="generator" content="Alpha Anywhere HTML Editor"> <title>Comments</title> </head> <body> <%a5 ' This line is an Xbasic comment and will not appear. ? "This line will appear." %> <p> <!-- This line is an HTML comment and will not appear. -> This line will appear. </body> </html>
Select File > Save As.
Enter "Comments" in the File name field and click Save .
Click 'x' to close the HTML Editor.
Display the A5W Pages page of the Web Projects Control Panel.
Right click the "Comments" entry and select Publish (Local Webroot) and open. Your new page will appear in your Internet browser. The results should look like this.