The standard datatypes in PocketBuilder are the familiar datatypes that are used in many programming languages, including char, integer, decimal, long, and string. In PowerScript, you use these datatypes to declare variables or arrays.
These are the standard PowerScript datatypes, followed by a description of each:
Binary large object. Used to store an unbounded amount of data (for example, generic binary, image, or large text such as a word-processing document).
Contains TRUE or FALSE.
A single ASCII character.
If you have character-based data that you will want to parse in an application, you might want to define it as an array of type char. Parsing a char array is easier and faster than parsing strings. If you will be passing character-based data to external functions, you might want to use char arrays instead of strings.
For more information about passing character-based data to external functions, see the Resource Guide. For information about datatype conversion when assigning strings to chars and vice versa, see “String and char datatypes in PocketBuilder”.
Using literals To assign a literal value, enclose the character in either single or double quotation marks. For example:
char c
c = 'T'
c = "T"
The date, including the full year (1000 to 3000), the number of the month (01 to 12), and the day (01 to 31).
Using literals To assign a literal value, separate the year, month, and day with hyphens. For example:
1992-12-25 // December 25, 1992
1995-02-06 // February 6, 1995
The date and time in a single datatype, used only for reading and writing DateTime values from and to a database. To convert DateTime values to datatypes that you can use in PocketBuilder, use:
The Date(datetime) function to convert a DateTime value to a PocketBuilder date value after reading from a database
The Time(datetime) function to convert a DateTime value to a PocketBuilder time value after reading from a database
The DateTime (date, time) function to convert a date and (optional) time to a DateTime before writing to a DateTime column in a database.
Signed decimal numbers with up to 18 digits. You can place the decimal point anywhere within the 18 digits—for example, 123.456, 0.000000000000000001 or 12345678901234.5678.
Using literals To assign a literal value, use any number with a decimal point and no exponent. The plus sign is optional (95 and +95 are the same). For numbers between zero and one, the zero to the left of the decimal point is optional (for example, 0.1 and .1 are the same). For whole numbers, zeros to the right of the decimal point are optional (32.00, 32.0, and 32. are all the same). For example:
12.34 0.005 14.0 -6500 +3.5555
A signed floating-point number with 15 digits of precision and a range from 2.2250738585073E-308 to 1.79769313486231E+308.
16-bit signed integers, from -32768 to +32767.
Using literals To assign a literal value, use any whole number (positive, negative, or zero). The leading plus sign is optional (18 and +18 are the same). For example:
1 123 1200 +55 -32
32-bit signed integers, from -2147483648 to +2147483647.
Using literals Use literals as for integers, but longer numbers are permitted.
64-bit signed integers, from -9223372036854775808 to 9223372036854775807.
Using literals Use literals as for integers, but longer numbers are permitted.
A signed floating-point number with six digits of precision and a range from 1.175495E-38 to 3.402822E+38.
Using literals To assign a literal value, use a decimal value, followed by E, followed by an integer; no spaces are allowed. The decimal number before the E follows all the conventions specified above for decimal literals. The leading plus sign in the exponent (the integer following the E) is optional (3E5 and 3E+5 are the same). For example:
2E4 2.5E78 +6.02E3 -4.1E-2
-7.45E16 7.7E+8 3.2E-45
Any ASCII character with variable length (0 to 2147483647).
Most of the character-based data in your application, such as names, addresses, and so on, will be defined as strings. PowerScript provides many functions that you can use to manipulate strings, such as a function to convert characters in a string to uppercase and functions to remove leading and trailing blanks.
For more information about passing character-based data to external functions, see the Resource Guide. For information about datatype conversion when assigning strings to chars and vice versa, see “String and char datatypes in PocketBuilder”.
Using literals To assign a literal value, enclose as many as 1024 characters in either single or double quotes, including a string of zero length or an empty string. For example:
string s1
s1 = 'This is a string'
s1 = "This is a string"
You can embed a quotation mark in a string literal if you
enclose the literal with the other quotation mark. For example,
the following statements result in the string Here's
a string
:
string s1
s1 = "Here's a string."
You can also use a tilde (~) to embed a quotation mark in a string literal. For example:
string s1 = 'He said, "It~'s good!"'
Complex nesting When you nest a string within a string that is nested in another string, you can use tildes to tell the parser how to interpret the quotation marks. Each pass through the parser strips away the outermost quotes and interprets the character after each tilde as a literal. Two tildes become one tilde, and tilde-quote becomes the quote alone.
Example 1 This string has two levels of nesting:
"He said ~"she said ~~~"Hi ~~~" ~" "
The first pass results in:
He said "she said ~"Hi ~" "
The second pass results in:
she said "Hi"
The third pass results in:
Hi
Example 2 A more probable example is a string for the Modify function that sets a DataWindow property. The argument string often requires complex quotation marks (because you must specify one or more levels of nested strings). To understand the quotation marks, consider how PocketBuilder will parse the string. The following string is a possible argument for the Modify function; it mixes single and double quotes to reduce the number of tildes:
"bitmap_1.Invert='0~tIf(empstatus=~~'A~~',0,1)'"
The double quotes tell PocketBuilder to interpret the argument as a string. It contains the expression being assigned to the Invert property, which is also a string, so it must be quoted. The expression itself includes a nested string, the quoted A. First, PocketBuilder evaluates the argument for Modify and assigns the single-quoted string to the Invert property. In this pass through the string, it converts two tildes to one. The string assigned to Invert becomes:
'0[tab]If(empstatus=~'A~',0,1)'
Finally, PocketBuilder evaluates the property’s expression, converting tilde-quote to quote, and sets the bitmap’s colors accordingly.
Example 3 There are many ways to specify quotation marks for a particular set of nested strings. The following expressions for the Modify function all have the same end result:
"emp.Color = ~"0~tIf(stat=~~~"a~~~",255,16711680)~""
"emp.Color = ~"0~tIf(stat=~~'a~~',255,16711680)~""
"emp.Color = '0~tIf(stat=~~'a~~',255,16711680)'"
"emp.Color = ~"0~tIf(stat='a',255,16711680)~""
Rules for quotation marks and tildes When nesting quoted strings, the following rules of thumb might help:
A tilde tells the parser that the next character should be taken as a literal, not a string terminator
Pairs of single quotes ( ' ) can be used in place of pairs of tilde double quotes (~")
Pairs of tilde tilde single quotes (~~'
)
can be used in place of pairs of triple tilde double quotes (~~~")
The time in 24-hour format, including the hour (00 to 23), minute (00 to 59), second (00 to 59), and fraction of second (up to six digits), with a range from 00:00:00 to 23:59:59:999999.
Using literals The time in 24-hour format, including the hour (00 to 23), minute (00 to 59), second (00 to 59), and fraction of second (up to six digits), with a range from 00:00:00 to 23:59:59.999999. You separate parts of the time with colons—except for fractional sections, which should be separated by a decimal point. For example:
21:09:15 // 15 seconds after 9:09 pm
06:00:00 // Exactly 6 am
10:29:59 // 1 second before 10:30 am
10:29:59.9 // 1/10 sec before 10:30 am
16-bit unsigned integers, from 0 to 65535.
32-bit unsigned integers, from 0 to 4294967295.