Previous in Contents Next in Contents

Commerce Server Object Parameters in VBScript

As you script Commerce Server sites, you should be particularly aware of two features of Microsoft® Visual Basic® Scripting Edition (VBScript) that figure prominently in the use of the methods implemented by Commerce Server objects.

First, as with other Microsoft® ActiveX® server objects, all variables passed to Commerce Server objects appear to VBScript as a single data type: Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used. Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript. If you call functions documented in this Object Reference from Visual Basic, you should declare the variables that you pass to these functions as Variants.

Second, many of the methods implemented in Commerce Server objects take optional parameters. This means that if you do not supply a value for these parameters, a default value is assumed. How you reference optional parameters depends upon a parameter's position in the parameter list.

The following example uses the DataFunctions object's ValidateNumber method to illustrate the various ways in which you use optional parameters. This method, which determines whether a value that you supply falls within a given numerical range, has the following syntax:

DataFunctions.ValidateNumber(Value, MinimumValue, MaximumValue)

The Value parameter references the number that you want to test against a set of range values. MinimumValue and MaximumValue designate the low and high ends of that range. If Value falls within the designated range, ValidateNumber returns True; otherwise, False.

However, because the MinimumValue and MaximumValue parameters are optional, you can call this method in several ways. For example, if you are interested only in determining whether the value that you have supplied exceeds a certain minimum, call ValidateNumber as follows:

bValid = datafunctions.ValidateNumber(Value, MinimumValue)

Because MaximumValue is not specified, its default value is assumed, which means that the parameter is ignored in the range evaluation.

If, however, you wanted to test a value against a maximum value, but not against a minimum value, you would call ValidateNumber as follows:

bValid = datafunctions.ValidateNumber(Value, Null, MaximumValue)

Note that you cannot simply eliminate the Null placeholder for MinimumValue in this case, because MinimumValue appears to the left, in the parameter list, of a value that you specify. This parameter's value is specified as Null, which means that the parameter is ignored in the range valuation, and Value is tested only against MaximumValue.

Finally, you can call ValidateNumber as follows:

bValid = datafunctions.ValidateNumber(Value)

In this case, you do not have to specify Null for either optional argument, because this call uses no optional argument that appears to the left of another, specified optional argument. Because both MinimumValue and MaximumValue appear at the end of the argument list, and are not referenced, both default to Null, which means that both values are ignored in the valuation.


© 1997-2000 Microsoft Corporation. All rights reserved.