A. Declarations
Statement Example Description
Var Number = 6 ; Initializing it to a value is Optional at the time of
Var N1, N2, N3 = 6; declaration.
Function extern function doIt Now ( ) Used to declare a function with
{ the specified parameters.
Statements To return a value the function must use the return statement. }; extern function do this (p1,p2,p3)
extern is used so that the function is available outside of where it is defined. { statements } ;
use use url script2
*http://www.somewhere.com/WMLS use is used to enable the script scripts/script2.wmls" ; to use pragmas (see table below).
B. Loops
Statement Example Description
For for (var 1=0; i<15; I++) Creates a loop controlled according to the three optional expressions enclosed { in the parentheses after the for and separated by semicolons. The first of x + = i; these three expressions is the initial-expressions, the second is the test
do something (x); condition, and the third is the increment -expression. }
if . . . else if (x < = y) Executes a block of statements if the condition evaluates to true. If the {condition evaluates to false, another
TOP
Statement Example Description
block of statements can be executed thing + = x; using else (this is optional).
x + + ;
}
Executes a block of statements if a test condition evalutes to true. The loop then { repeats, testing the condition with each repeat, ceasing if the condition evaluates
dosomething(); to false. }
{ control to the statement following the loop.
if (10 = = x)
break;
x++;
}
return x*b;
statements in the current iteration of a while or for loop; execution of the loop
{continues with the next iteration.
if (0 = = (++ count % 2))
continue;
return count*c;
}
returnSthg (x,y)
{
}
Pragmas
Pragma Example Description
url use url ID "URL" Used to specify the URL of the WMLScript file containing the functions we want to use, in URL, and can then access these functions using the name specified in ID.
access use access domain Used to specify the domain and "domin" path "path" path from which access is allowed to function in the current WMLScript.
meta use meta type property Used to supply additional information. content scheme type represents the type of pragma,property the name of the header you wish to set, content the value you want to set the header, and scheme the formatting of the header
Comment
Comments are notes which the scrip engine ignores, and which can be used to explain the code.
//this is the syntax for a one line comment_
/* and this is the syntax for a multiple line comment. The comment can be of any length, as long as it is contained within the "star slash" brackets */
TOP
Escape Codes
The following table lists all the literal string escape codes.
Escape Code Represents
\' Single quote
\" Double quote
\\ Backslash
\ / Frontslash
\b Backspace
\f Newline
\r Carriage return
\t Horizontal tab
\xhh Character hh from the Latin -1 character set (ISO 8859-1) hexadecimal format as two digits
\ooo Character ooo form the Latin-1 character set (ISO 8859-1) format as three digits
\uhhhh Character hhhh from the Unicode character set, (ISO 8859-1) format as four digits
Standard WMLScript Library Functions
Dialogs
This library contains functions used to produce simple use interface cards.
Alert
Usage: alert(message)
Parameters: message-of type string, the warning to be displayed to the user
Comments: This function displays the message passed to it as a warning and when the user confirms they have read the message returns them to the previous card
Example: Dialogs.alert ("There has been an error");
Confirm
Usage: confirm(message, ok, cancel)
Parameters: message-of type string, the positive option to offer the user
Cancel-of type string, the negative option to offer the user
Comments: a Boolean, true if the user chooses ok, false if they choose cancel Confirmation, is required.
Example: bleResult = Dealogs.confirm("Are you sure you wish to do this "Yes", "Not really");
Prompt
Usage: prompt(message, default)
Parameters: message-of type string, the text to display prompting the user for input default-of type string, the default text to fill to input box with
Comments: This function just presents the user with an input box to fill.
Example: strResult = Dialogs.prompt ("Enter your name", "Bob");
Float
This library contains functions for the manipulation and conversion of floating point
numbers.
Ceil
Usage: ceil(value)
Parameters: value - a floating point number
Returns: An integer, which is nearest in size to the value, but not smaller than it.
Comments: Be careful when using negative numbers, ceil(2.7)=and NOT-3
Example: x = Float.ceil (4.1);
// x is assigned the value 5
floor
Usage: floor(value)
Parameters: value- a floating point number
Returns: An integer, which is nearest in size to the value, but not greater than it
Comments: Be careful when using negative numbers, floor(-4.1)= -5 and NOT -4
Example: x = Float.floor (1.9) ;
Int
Usage: int(value)
Parameters: value-a floating point number
Returns: The integer part of the floating point value Comments: This simply returns the integer part of the
value; it doesn't round the number
Example: x = float.int(2.9) ;
// x is assigned the value 2 |