Build an automation that executes a Microsoft Visual Basic script. Use the package to end the automation if it fails, making it resilient to deployment failures. A resilient automation allows scheduled and queued tasks to continue even when it encounters any deployment errors.

In this automation, you ask the user to provide a number. The automation passes the number to a Microsoft Visual Basic script to multiply by pi and return the value. The automation then reports the result to the user. You can use the VBScript package to either import an external script or enter it directly into your automation. In this example, you manually enter the script. You also add resiliency to the automation by adding error handling.

Procedure

  1. Create Task Bot.
    1. On the left panel, click Automation.
      A list of available automations and forms is displayed.
    2. Click Create New > Task Bot.
    3. Provide a name for the Task Bot: MultiplyPi
    4. Click Create and Edit.
  2. Create the following variables:
    • First variable
      • Name: nPromptAnswer
      • Type: Number
    • Second variable
      • Name: lNumbersForPi
      • Type: List
      • Subtype: Number
    For more information on creating a variable, see Create a variable.
  3. Click Save.
  4. Use the For value action to prompt the user for a number.
    1. Double-click or drag the Prompt > For value action to add it to the automation.
    2. In the Prompt window caption field, enter Any Number.
    3. In the Prompt message field, enter Enter any number to multiply by pi.
    4. Click the Assign the value to a variable drop-down menu and select SampleString.
    5. Click Save.
  5. Use the Try action to end the automation if the user does not enter a number when prompted.
    1. Double-click or drag the Error handler > Try action.
    2. Drag the Prompt > For value action under the Error handler > Try action.
    3. Click Save.
  6. Convert the SampleString (string) to a number value.
    1. Double-click or drag the String > To number action, adding it as the last line before the Error handler > Catch action.
    2. In the Enter the string field, press F2 to open the list of your variables, and select SampleString.
    3. Click Insert.
    4. Click the Assign the output to variable drop-down menu and select nPromptAnswer.
    5. Click Save.
  7. Copy the number value to the first item in the list of numbers to pass to VBScript.
    1. Double-click or drag the List > Add item action to the last line before the Error handler > Catch action.
    2. Click the List variable drop-down menu and select lNumbersForPi.
    3. Click the Item to be added drop-down menu and select nPromptAnswer.
    4. Click Save.
  8. Use the Open action to provide your Visual Basic source code.
    1. Double-click or drag the VBScript > Open action to the last line before the Error handler > Catch action.
    2. In the VBScript field, select the Manual Input radio button.
    3. Copy the following code and paste it into the Enter script here field:
      Dim Arg, var1, var2
      Set Arg = WScript.Arguments
      Function MultiplyPi(Arg)
        var1 = Arg(0)
        var2 = 3.14159
        MultiplyPi = cdbl(var1)*var2
      End Function
    4. Click Save.
  9. Use the Run function action to execute the script.
    1. Double-click or drag the VBScript > Run function action to the last line before the Error handler > Catch action.
    2. In the Enter the name of the function to be executed (optional) field, enter MultiplyPi.
    3. Click the Parameters (optional) drop-down menu and select lNumbersForPi variable.
    4. Click the Assign the output to variable (optional) drop-down menu and select SampleString.
    5. Click Save.
  10. Use the Close action to end the session.
    1. Double-click or drag the VBScript > Close action to the last line before the Error handler > Catch action.
    2. Click Save.
  11. Display the answer generated in the VBScript on the screen.
    1. Double-click or drag the Message box action to the last line before the Error handler > Catch action.
    2. In the Enter the message to display field, enter Pi times your number is:.
    3. Press F2 to open the list of your variables, and select SampleString.
    4. Click Insert.
    5. Click Save.
  12. Notify the user if an error occurred before terminating the automation.
    1. Double-click or drag the Message box action under the Error handler: Catch AllErrors.
    2. In the Enter the message to display field, enter Bot failed. Please be sure to enter only numbers..
    3. Click Save.
  13. Click the List tab to view your code as text only.
    Your code should look like this:
    Start
    Error handler: Try
        Prompt: For value during bot execution and assign the value $SampleString$
        String: To number Convert string $SampleString$ to a number and assign it to number variable $nPromptAnswer$
        List: Add item $nPromptAnswer$ to $lNumbersForPi$
        VBScript: Open VBScript manual script of 7 lines
        VBScript: Run function "MultiplyPi"
        VBScript: Close VBScript "Default"
        Message box "Pi times your number is: $SampleString$"
    Error handler: Catch AllErrors
        Message box "Bot failed.  Please be sure to enter only numbers."
    End
  14. Run your automation.
    When the automation is deployed, the prompt window opens where you enter the value, and then the message box displays the calculated number.

    Entering the value in the Prompt window

    Calculated values displayed in the message box

  15. Click Close
    You can test the resiliency of your Task Bot by running it again and entering a string value instead of a number when prompted.