Desktop User Guides > Professional > Interview scripting > Sample management > Sample management facilities > Sample management scripts > Converting .sam scripts into .mrs format
 
Converting .sam scripts into .mrs format
Differences between UNICOM Intelligence scripting and VBScript
Read How does mrScriptBasic compare to VBScript?, and make the changes described in that topic.
Write an error handler to deal with errors and add the following statement that tells sample management to use the error handler when errors occur:
On Error GoTo ErrorHandler
This syntax is available in mrScriptBasic but not in VBScript. For more information, see On Error.
Use the IsNullObject function rather than Is Nothing when comparing objects. Set an object to Null rather than Nothing to release it or indicate that it is not set.
Use While…End While instead of While…Wend.
Differences between the UNICOM Intelligence and VBScript sample management objects
The VBScript objects support UtcNow. In UNICOM Intelligence scripts use Now("UTC"). (All the functions in the UNICOM Intelligence Function Library are available for use in sample management scripts.)
Use Log.Log rather than Log.LogThisEx for logging.
Access the logging enums using logLevels.LOGLEVEL_INFO rather than LOGLEVEL_INFO
Use the SampleResult parameter (SampleResult.Code = RESULT_SUCCESS) rather than the function (AuthenticateSampleRec = SUCCESS) to return success or failure
The return codes (SUCCESS, FAILURE, REJECT, NO_RECORDS) are not defined intrinsically but must be defined as global constants or variables. Use the following definitions to ensure that the values match what is expected by the system:
' SampleResult.Code values set to indicate script status
Const RESULT_SUCCESS = 0
Const RESULT_FAILURE = 1
Const RESULT_REJECT = 2
Const RESULT_NO_RECORDS = 3
Instead of returning the sample record through a SampleRec parameter to the function, return it through the SampleResult parameter (SampleResult.SampleRec).
Function signatures have changed as follows:
VBScript
UNICOM Intelligence scripting
Function AuthenticateSampleRec(SampleFields, SampleRec)
Sub AuthenticateSampleRec(SampleResult, SampleFields)
Function ReturnSampleRec(SampleRec, SampleRecReturnCode)
Sub ReturnSampleRec(SampleResult, SampleRecReturnCode)
Function GetSampleRec(SampleFields, SampleRec)
Sub GetSampleRec(SampleResult, SampleFields)
This also means that Exit Function must be changed to Exit Sub.
Differences between functions available to UNICOM Intelligence and VBScript
Conversion functions have different names:
VBScript
UNICOM Intelligence scripting
CBool
CBoolean
CStr
CText
Date manipulation functions have parameters in a different order.
VBScript
UNICOM Intelligence scripting
DateAdd(Interval, Count, Val)
DateAdd(Val, Interval, Count)
DatePart(Interval, Val)
DatePart(Val, Interval)
Use Find instead of InStr. Find is 0-based; InStr is 1-based. Also, Find has the start index parameter at the end; InStr has it at the beginning.
The UNICOM Intelligence VarType function returns different numbers for the same types. Strings are returned as 2 instead of 8, booleans are returned as 7 instead of 11, and categoricals are returned as 3 instead of 9 (Object).
Differences in the UNICOM Intelligence version of the standard scripts
The UNICOM Intelligence versions avoid use of On Error Resume Next. Instead they use On Error GoTo ErrorHandler as recommended earlier. The error handler logs a message and exits with a FAILURE code.
When attempting to find an object in a collection, the VBScript versions set the object to Nothing, then attempt retrieve it. On Error Resume Next is used so if the attempt to retrieve the object fails, it is set to Nothing. So after the attempt to retrieve the object, it is checked against Nothing.
Two other functions, GetStringValue and GetIntValue, have been added to the UNICOM Intelligence scripts. These make it make it easy to return "" if a string property does not exist, and 0 if an integer (UNICOM Intelligence Long) property does not exist.
See also
Sample management scripts