|
Assigns NAME variable a VALUE given by expression or literal. The vaiable can also be an array or member of a structure.
Variable names must follow specific naming conventions and are normally prefixed with a character and period indicating the scope of the variable. (e.g. s, l, d, or g) See Variables for a complete description. Attributes
ExamplesAssign a global variable an literal string and out put it to the browser. Example:
<MvASSIGN NAME="g.name" VALUE="Dana Scully">
<MvEVAL EXPR="{ g.name }"><br>
Result: Dana Scully
Building on the previous example, assign a global variable a string expression and out put it to the browser. Example:
<MvASSIGN NAME="g.greeting" VALUE="{ "Hi Agent " $ gettoken(g.name,' ',2) $ ','">
Result: "Hi Agent Scully,"
Numeric expressions. Example:
<MvASSIGN NAME="l.age" VALUE="7">
<MvASSIGN NAME="l.next_age" VALUE="{ l.age + 1 }">
<MvASSIGN NAME="l.current_age" VALUE="{ l.thisyear - l.birthyear }">
Miva Script variable data types are not explicitly declared, meaning you can sometimes combine them to your benefit or inadvertently introduce bugs in your runtime program. Example:
<MvASSIGN NAME="g.Age" VALUE="7">
<MvASSIGN NAME="g.Name" VALUE="Avery">
<MvEVAL EXPR="{ g.Name $ ' is ' $ g.Age }">
Result: Avery is 7
<MvEVAL EXPR="{ g.Name $ ' will be ' $ g.Age + 1 }">
Result: Compiler Error: Operator type does not match constant type;
<MvEVAL EXPR="{ g.Name $ ' will be ' $ g.Age + 1 }">
Instead use:
<MvEVAL EXPR="{ g.Name }"> will be <MvEVAL EXPR="{ g.Age + 1 }"><br>
Result: Avery will be 8
Array AssignmentArrays and structures are used to store multiple values in a single variable. They can consist of a simple indexed list of values or more complex spreadsheet or database like structures. See Arrays This list of month names is access using a numeric index. In expressions array indexes are expressed using brackets [n]. Example:<MvASSIGN NAME = "g.num" VALUE = 1>
<MvASSIGN NAME = "g.Months" INDEX = "1" VALUE = "January" >
<MvASSIGN NAME = "g.Months" INDEX = "2" VALUE = "February" >
<MvEVAL EXPR="{ g.month[g.num] }">
Result: January
<MvASSIGN NAME = "g.num" VALUE = "{ g.num + 1 }" >
<MvEVAL EXPR="{ g.month[g.num] }">
Result: February
Variable names can be grouped like a database records or spread sheet row using the MEMBER attribute. In expressions members are represented using the colon character " : ". Example:<MvASSIGN NAME = "g.Month" INDEX = "{ 1 }" MEMBER = "Name" VALUE = "January">
<MvASSIGN NAME = "g.Month" INDEX = "{ 1 }" MEMBER = "Abr" VALUE = "Jan">
<MvASSIGN NAME = "g.Month" INDEX = "{ 1 }" MEMBER = "Length" VALUE = "31">
<MvEVAL EXPR="{ g.month[1]:Length }">
Result: 31
Members can be assigned directly in the NAME attribute, simplifying the syntax. Example:<MvASSIGN NAME = "g.email:to" VALUE = "yo@mimi.com">
<MvASSIGN NAME = "g.email:to_name" VALUE = "Yo Yo Ma">
<MvASSIGN NAME = "g.email:from" VALUE = "mimi@mimi.com">
<MvASSIGN NAME = "g.email:from_name" VALUE = "Mimi Fox">
<MvASSIGN NAME = "g.email:subject" VALUE = "Yo Yo Yo Lets get together!">
<MvEVAL EXPR="{ send_my_email(g.email) }">
|