The Lang library contains functions closely related to the WMLScript language core.
Description: This function will interrupt the processing of the WMLScript and return the value of errorDescription (which must be a string) to the device.
Syntax: Lang.abort(errorDescription)
Example: The following example interrupts WMLScript processing, and displays the error message:
// Compare passwords if (password1!=password2) { // Passwords do not match Lang.abort("Passwords do not match!"); }
Description: This function returns the absolute value of a specified number. If value is of type integer, then the result is of type integer. If value is of type floating point, then the result is of type floating point. If value is not one of these types, then "invalid" is returned.
Example: The following example returns the absolute value of the value of a specified variable:
// Get absolute value of a var b=Lang.abs(a);
Description: The Internet Assigned Numbers Authority (IANA) has assigned integer values for all character sets. CharacterSet returns this value.
Example: The following example checks and returns the character set supported by the WMLScript interpreter:
// Check character set function charSetTest() if (Lang.characterSet() == 4){ return ("Western Europe!"); } else { return ("Unknown"); }
Description: This will end the rendering of the WMLScript code and present the string value. You can use this function to normally exit your WMLS code where needed.
Example: The following example exits the current WMLScript and returns the specified string to the device:
// Check if okay to proceed, exit if not if (!proceed){ Lang.exit("Cannot proceed as requested"); }
Description: This function returns either true or false. If floating points are supported, the result is true. Otherwise, the result is false.
Example: The following example returns true if floating points are supported by the WAP browser:
// Check if floating point is supported before continuing if (!Lang.float()){ Lang.abort("Cannot perform calculation, floating point operations are not supported"); }
Description: If value can be converted into a floating point, this function returns true. Otherwise, the result is false.
Example: The following converts a floating point number to its closet integer (if it is a floating number):
// Is "a" a float? if (Lang.isFloat(a)){ // Yes it is, convert to integer var b=Float.round(a); }
Description: If value can be converted into an integer, this function returns true. Otherwise, the result is false.
Example: The following example checks to see that a specified value is an integer (and not a float); if it is not it prompts for the value again:
// Is "a" an int? if (!Lang.isInt(a)){ // Prompt for it again a=Dialogs.prompt("Please enter a valid integer value", ""); }
Description: Evaluates two values and determines which is the larger number. Whether the result is an integer or floating point is determined by the type of value1 and value2.
Syntax: Lang.max(value1,value2)
Example: The following example saves the greater of two specified values:
// Get greater value var a = Lang.max(var1, var2);
Description: This will return the largest supported integer value.
Example: The following example initializes an integer value to the highest support value:
// Initialize to greatest possible value var a=Lang.maxInt();
Description: Evaluates two values and determines which is the smaller number. Whether the result is an integer or floating point is determined by the type of value1 and value2.
Syntax: Lang.min(value1,value2)
Example: The following example saves the lesser of two specified values:
// Get lesser value var a = Lang.min(var1, var2);
Description: This will return the smallest supported integer.
Example: The following example initializes an integer value to the smallest support value:
// Initialize to smallest possible value var a=Lang.minInt();
Description: Converts a string to type floating point. Parsing ends at the first character that cannot be parsed.
Syntax: Lang.parseFloat(value)
Example: The following example returns 2.500000e+000:
// Prompt for temperature and parse into a float var temp=Lang.ParseFloat(Dialogs.prompt("Temperature:",""));
Description: Converts a string to type integer.
Example: The following example returns the house number portion of an address:
// Get house number var house_num=Lang.parseInt(address1);
Description: Generates a random integer greater or equal to 0 and less than or equal to a specified value.
Example: The following example is a function that will return a random number between 0 and 100:
// Return a random number between 0 and 100 function GetRandom(){ return Lang.random(100); }
Description: This initializes a random numeric sequence and also returns an empty string. If value is of type floating point, then Float.int() should be used first to convert the value to an integer.
Example: The following will initialize the random numeric sequence based on the number 42:
// Initialize random sequence Lang.seed(42);
3.145.166.7