MvASSIGN#
Assigns NAME variable a VALUE given by expression or literal. The variable can also be an array or member of a structure.
<MvASSIGN NAME = "string: { expression } | literal"
VALUE = "{ expression } | literal"
INDEX = "numeric: { expression } | literal"
MEMBER = "string: { expression } | literal">
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#
Attribute | Description |
---|---|
NAME |
(Required) The name assigned to the variable. Normally a literal, but can also contain an expression that results in a variable name. For example { g.varname } where g.varname = l.item[10] . |
VALUE |
(Required) The expression or literal for the named variable. |
INDEX |
(Optional) The expression or literal for the index to a variable array. |
MEMBER |
(Optional) The expression or literal for the member to a variable structure. |
Examples#
Assign a literal string#
<MvASSIGN NAME="g.name" VALUE="Dana Scully">
<MvEVAL EXPR="{ g.name }"><br>
Assign a string expression#
<MvASSIGN NAME="g.greeting" VALUE="{ "Hi Agent " $ gettoken(g.name,' ',2) $ ','}">
Numeric expressions#
<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.
Data type mismatch example#
<MvASSIGN NAME="g.Age" VALUE="7">
<MvASSIGN NAME="g.Name" VALUE="Avery">
<MvEVAL EXPR="{ g.Name $ ' is ' $ g.Age }">
Compiler Error
<MvEVAL EXPR="{ g.Name $ ' will be ' $ g.Age + 1 }">
Wrong
<MvEVAL EXPR="{ g.Name $ ' will be ' $ g.Age + 1 }">
Correct
<MvEVAL EXPR="{ g.Name }"> will be <MvEVAL EXPR="{ g.Age + 1 }"><br>
Array Assignment#
Arrays 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 accessed using a numeric index. In expressions, array indexes are expressed using brackets [n]
.
<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.Months[g.num] }">
<MvASSIGN NAME="g.num" VALUE="{ g.num + 1 }">
<MvEVAL EXPR="{ g.Months[g.num] }">
Variable names can be grouped like database records or spreadsheet rows using the MEMBER attribute. In expressions, members are represented using the colon character :
.
<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 }">
Members can be assigned directly in the NAME attribute, simplifying the syntax:
<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) }">