Developer Documentation Library > Scripting > mrScriptBasic overview > mrScriptBasic language reference > Statements > With
 
With
A With statement runs a series of statements on a single object.
Syntax
With objectexpression statements End With
Arguments
objectexpression
Name of an object or an expression that returns an object.
statements
One or more statements that are executed on the object.
Remarks
The With statement performs a series of statements on a specified object without requalifying the name of the object. For example, to change a number of different properties on a single object, put the property assignment statements inside the With control structure, referring to the object once instead of referring to it with each property assignment.
While property manipulation is an important aspect of With functionality, it is not the only use. Any legal code can be used in a With block.
After a With block is entered, the object cannot be changed. As a result, you cannot use a single With statement to affect a number of different objects.
You can nest With statements by putting one With block inside another. However, because members of outer With blocks are masked within the inner With blocks, you must provide a fully qualified object reference in an inner With block to any member of an object in an outer With block.
Do not jump into or out of With blocks. If statements in a With block are executed, but either the With or End With statement is not executed, you might get errors or unpredictable behavior.
Examples
The following example uses a With block to set property values when creating a new variable in an MDM Document. To run this example using the mrScript Command Line Runner, use the /m: option to specify the Short Drinks sample .mdd file.
Dim MyVariable

MDM.Open ("[INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\short_drinks.mdd")
Set MyVariable = MDM.CreateVariable("Spend", "How much do you spend on our products per year?")

With MyVariable
  .DataType = mr.Long
  .MinValue = 0
   .MaxValue = 1000
End With

MDM.Fields.Add (MyVariable)
MDM.Save("[INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Output\short_drinks.mdd")
MDM.Close()
The following example uses a With block to define several aspects of the Rating question, while specifying the name on the question only once.
Dim Wine
For Each Wine in WinesTasted
With Rating[Category]
.Label.Inserts["WineName"] = Wine
.Style.Color = mr.Blue
.Ask()
End With
Next
See also
Statements