Factorial of a Number Using VBScript

This process calculates the factorial of a number using VBScript.

Display.InputDialog Title:'Factorial' \
                    Message:'Number for factorial' DefaultValue:1 \
                    InputType:Display.InputType.SingleLine \
                    IsTopMost:False \
                    UserInput=> UserInput \
                    ButtonPressed=> ButtonPressed

System.RunVBScript VBScriptCode:'''Dim n,f 
                        n='''+UserInput+'''
                        f=1 
                        For i=1 to n 
                        f=f*i 
                        Next 
                        Wscript.Echo f''' \
                    ScriptError=> ScriptError \
                    ScriptOutput=> VBScriptOutput

Display.ShowMessage Title:'Result' \
                    Message:'Fact('+UserInput+')= '+VBScriptOutput \
                    Icon:Display.Icon.Information \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:True \
                    ButtonPressed=> ButtonPressed2

In more detail:


The process prompts the user to enter a number, then executes a custom VBScript code that calculates its factorial and finally displays the result.

Step 1: Prompt the User to Enter a Number

Prompt the user to enter the number whose factorial will be calculated.

Display.InputDialog Title:'Factorial' \
                    Message:'Number for factorial' DefaultValue:1 \
                    InputType:Display.InputType.SingleLine \
                    IsTopMost:False \
                    UserInput=> UserInput \
                    ButtonPressed=> ButtonPressed

Use the “Display.SelectFile”action and set the Dialog title and message.

Step 2: Execute a VBScript code

Calculate the factorial of the given number and inform the user of the result.

System.RunVBScript VBScriptCode:'''Dim n,f 
                        n='''+UserInput+'''
                        f=1 
                        For i=1 to n 
                        f=f*i 
                        Next 
                        Wscript.Echo f''' \
                    ScriptError=> ScriptError \
                    ScriptOutput=> VBScriptOutput

Display.ShowMessage Title:'Result' \
                    Message:'Fact('+UserInput+')= '+VBScriptOutput \
                    Icon:Display.Icon.Information \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:True \
                    ButtonPressed=> ButtonPressed2
  1. Use the “System.RunVBScript” to execute the VBScript code:
    1. Set the “VBScriptCode” argument to the respective code. Note that three quotes are used to declare a multiple line text variable. Additionally, the plus (+) sign is used to concatenate the “UserInput” variable with the VBScript code.
    2. Store the result to the “VBScriptOutput” variable.
  2. Use the “Display.ShowMessage” action to inform the user of the result:
    1. Set the dialog’s title and message.
    2. Use the plus (+) sign to concatenate the “VBScriptOutput” variable with the message’s text.
    3. Set the “IsTopMost” argument to “True”, so that the message box will remain on top of all other windows.
    4. Store the text of the button pressed in the “ButtonPressed2” output variable, to distinguish it from the “ButtonPressed” variable of the “Display.InputDialog” action used in the first step.