Syntax
|
Variables are General purpose objects. Basic data types : string, numeric and real are supported implicitly. var {objectname}
{objectname}({property}) {objectname}({property})={value}; //{value} is either a quoted string
or a property of an object;
{objectname}({property})={value1} {objectname}({property})={value2} {objectname}({property})={valueN} {objectname}({property}(00)) {objectname}({property}(0NN)) ;// N is a digit 0-9
|
Text
|
Variables are declared with the var statement.Variables in the Caravan script store values for later use.You need to define a variable and then assign values to it.
Rules * Variable names must begin with a letter. * Variable names must contain only letters, numbers and the underscore character (_). * Punctuation characters and spaces are not allowed. * Variable names must not exceed 40 characters. * Variable names cannot be a reserved word. * Numeric values must also be enclosed in double quotes ("). * When a variable is declared within a web page, only the Caravan script within that web page can access or change the value of that variable; it has a scope that is local to that web page. * Local variables declared with var remain in existence only as long as the web page is executing.
|
Sample
|
<caravan> var temp temp(Name)="John" temp(Age)="30" </caravan>
Name - variable name, this is assigned a value "John". Age - variable name, this is assigned a value "30".
In Caravan script, an array of variables is automatically created when one assigns multiple values to a variable. Arrays allow you to refer to a series of variables by the same name and use a number (an index) to tell them apart. All elements in an array have the same data type. Method 1 <caravan> var temp temp(name)="John" temp(name)="Chris" temp(name)="Mary" "No of Names =" ;temp(name(00)) ; "1 :" ;temp(name(01)) ; "2 :" ;temp(name(02)) ; "3 :" ;temp(name(03)) ; </caravan>
Method 2 <caravan> var temp temp(name(01))="John" temp(name(02))="Chris" temp(name(03))="Mary" "No of Names =" ;temp(name(00)) "1 :" ;temp(name(01)) ; "2 :" ;temp(name(02)) ; "3 :" ;temp(name(03)) ; </caravan>
Method 3 <caravan> var temp temp(delim)="," // coma is used as the delimiter temp(name)="John,Chris,Mary" "No of Names =" ;temp(name(00)) "1 :" ;temp(name(01)) ; "2 :" ;temp(name(02)) ; "3 :" ;temp(name(03)) ; </caravan>
In the above example, temp(name(00)) specifies the number of elements in the array. The individual elements of the variable can be addressed as temp(name(01)), temp(name(02)), and so on. temp(name(00)) will return a value of 3, denoting that this variable has 3 elements.
The other elements in the array can be accessed as temp(name(01)) which contains a value "John", temp(name(02)) which contains a value "Chris",temp(name(03)) which contains a value "Mary".
Variables defined can be used in active web pages in conditional statements, assigned to database fields, assigned to other variables, or used to increment or decrement the variable. The contents of the variable can be accessed in the following manner.
Examples Delete Variable object
<caravan> var temp temp(name)="John" temp(age)="30" "Name is ";temp(name);" age is ";temp(age); delete temp </caravan>
Note: Temporary variables used in a web page will be automatically deleted after the execution of that page. Delete and reuse Variable value
<caravan> var temp temp(name)="John" temp(age)="30" "Name is ";temp(name);" . Age is ";temp(age); temp(name)="null" temp(age)="null" temp(name)="Mary" temp(age)="26" "Name is ";temp(name);" . Age is ";temp(age);"<CARAVAN>" </caravan>
Note: Before a new value is assigned to a temporary variable, the value must be made null.
Deleting array elements <caravan> Var temp temp(name)="John" temp(name)="Chris" temp(name)="Mary" "No of names=";temp(name(00)) temp(name(02))="null" //removes the name "Chris" from the array. "No of names=";temp(name(00)) </caravan>
Increment <caravan> var temp temp(val)="0" temp(val(01))+="1" "Value is ";temp(val) </caravan>
Decrement <caravan> var temp temp(val)="1" temp(val(01))-="1" "Value is ";temp(val) </caravan>
Adding strings <caravan> Var temp temp(firstname)="Chris" temp(lastname)="Johnson" temp(fullname)= temp(firstname) temp(fullname(01))+= " " temp(fullname(01))+= temp(lastname) "Full name is "; temp(fullname) </caravan>
Note: Non-existent variables cannot be assigned or compared. In such cases, the Caravan Business Server displays an error.
<caravan> Var temp temp(firstname)="Chris" temp(fullname)= temp(firstname) temp(fullname(01))+= " " temp(fullname(01))+= temp(lastname) "Full name is "; temp(fullname) </caravan>
Note: The above example will give you script execution error. As variable temp(lastname) is non existent. To overcome such problems, the following method should be adopted.
<caravan> Var temp temp(firstname)="Chris" temp(fullname)= temp(firstname) temp(fullname(01))+= " " if temp(lastname) temp(fullname(01))+= temp(lastname) endif "Full name is "; temp(fullname) </caravan>
|
Quick Reference
|
|
Properties
|
Use of Delim
Arithmatic
Decimal Numbers / Real Numbers
|
Home
Back
|
|