Lang Library

The Lang library contains functions closely related to the WMLScript language core.

abort

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!");
}

abs

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.

Syntax: Lang.abs(value)

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);

characterSet

Description: The Internet Assigned Numbers Authority (IANA) has assigned integer values for all character sets. CharacterSet returns this value.

Syntax: Lang.characterSet()

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");
    }

exit

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.

Syntax: Lang.exit(value)

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");
}

float

Description: This function returns either true or false. If floating points are supported, the result is true. Otherwise, the result is false.

Syntax: Lang.float()

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");
}

isFloat

Description: If value can be converted into a floating point, this function returns true. Otherwise, the result is false.

Syntax: Lang.isfloat(value)

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);
}

isInt

Description: If value can be converted into an integer, this function returns true. Otherwise, the result is false.

Syntax: Lang.isInt(value)

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", "");
}

max

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);

maxInt

Description: This will return the largest supported integer value.

Syntax: Lang.maxInt()

Example: The following example initializes an integer value to the highest support value:

// Initialize to greatest possible value
var a=Lang.maxInt();

min

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);

minInt

Description: This will return the smallest supported integer.

Syntax: Lang.minInt()

Example: The following example initializes an integer value to the smallest support value:

// Initialize to smallest possible value
var a=Lang.minInt();

parseFloat

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:",""));

parseInt

Description: Converts a string to type integer.

Syntax: Lang.parseInt(value)

Example: The following example returns the house number portion of an address:

// Get house number

var house_num=Lang.parseInt(address1);

random

Description: Generates a random integer greater or equal to 0 and less than or equal to a specified value.

Syntax: Lang.random(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);
}

seed

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.

Syntax Lang.seed(value)

Example: The following will initialize the random numeric sequence based on the number 42:

// Initialize random sequence
Lang.seed(42);

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.166.7