Tuesday, January 10, 2012

QTP : Parameterization

The process of replacing  fixed value with parameter is called as parametrization where a parameter is a value that is assigned by external data source or generator. QTP enables you to expand  the scope of a basic test by replacing fixed values with parameters. This process is known as parametrization, which greatly increases the power and flexibility of your test.

Types of Parameters
Depending on the source of data, parametrization is divided  into 4 categories.
  1. Data Table parametrization
  2. Test/Action parametrization
  3. Environment variable parametrization
  4. Random number parametrization
Data Table Parametrization
This enables you to create a data driven test that runs several times using the data you supply. In each repetition or iteration, QTP uses different values from the Data Sheets of the Data Table. The Data Table has two types of data sheets- Global and Action.
             
Global sheet contains the data that is available to all actions. Action sheet contains the data that is available to specific action. Below is the script to search a specified keyword from Google Search :



  1.  To do this from keyword view, select  the cell which contains QTP  and click on symbol.




  2. Value Configuration Option Dialog as shown below will be displayed. select the parameter as Data Table, Sheet as Global Sheet and Name of the column to store data as SearchKeyword.
  3. A new column SearchKeyword will be created in the Global Sheet. Add keywords to search in this column. After entering the data, the global sheet looks as below:         
                     
  4. Click Run button. You can see that the test runs 4 iterations and each iteration uses one search keyword from the list above.

  5. The number of iterations the test runs can be controlled from File>Settings>Run dialog.



    Run one Iteration only: Runs Test Script one iteration only irrespective of the number of rows in the Global Sheet.
    Run on all rows:
    Test Script iterations depend on the number of rows in Global Sheet. For example 4 rows in the Global Sheet means the test iterations for 4 times.
    Run from row X to row Y: The test iterates to the difference between X and Y. If Y is 10 rows and X is 5 rows the test iterates 5 times.

    Steps to do data table parametrization:
    1. Select sheet as Local Sheet.
    2. A new column SearchKeyword will be created in the Local Sheet-Action1. Add keywords to search in this column. After entering the data the action1 sheet looks like this:
    3. Click Run button and observe that the script searches for only the first keyword in the column. This is because iteration settings of action points to Run One Iteration Only by default.
    4. To change the action iteration settings, select View>Test Flow. This opens the test flow pane, Right click on Action node in test flow pane and select Action Call Properties from the menu.

      It will open Action call properties dialog as shown below:
    5. Now Run the script and observe the script searches for all keywords.


    Test/Action Parameters
    Test/Action parameters enables you to use values passed from calling action to called action. say if we create a login action and made it reusable, this login action can be called from any other action. Limitation is that calling action has to use the username and password which is a part of login action. This limitation can be eliminated by Parameterizing the action in such a way that it takes input parameters as username and password.
  1. Create a login action for Gmail, Login code looks like as shown below, username is syedarmani :

  2. Right click on the action node and select action properties. The Action properties dialog box will appear. Select parameters>Input Parameters and click + symbol and add uname and passwd as their parameters and their type as string and password respectively. Action properties dialog looks as below and click OK.


     
  3. Now your action is ready with two input parameters uname and passwd. you must use these input parameters in the script. From the script shown above, text syedarmani in line1 must be parametrized with uname and line2 must be parametrized with passwd.
  4. To do this from keyword view, select the cell which contains syedarmani and Click on symbol.
  5. Value Configuration Option Dialog as shown below will be displayed. Select parameter as Test/Action parameter and parameter name as uname.
                  
  6. Repeat steps 4-5 for password also.
  7. Now the action with parameters is ready to use by any calling action. Save this in a script as S1.
  8. Now let us call the Login Action of script S1 from script S2 and pass the parameter values. Steps for this are as shown below:
    • Create new script S2 and select Insert>Call To Existing Action
    • From Select Action dialog select the From test as S1 and Action as Login.
    •  Click OK. This adds a statement to call login action of script S1 from S2. The statement will be as shown below:
      RunAction "Login[S1]" oneIteration
    • Right Click on node Login and select Action Call Properties. This displays Action Call Properties Dialog. Select the Property Values tab and enter uname as DemoUser and password Demo123. The dialog appears as below
    • Now script S2 calls Action Login from script S1 and passes username and password as Demo User and Demo123.  
    Benefits of Parametrization
    Using Parametrization you can   
    1. Parametrize values in steps.
    2. Parametrize values of action parameters.
    3. Parametrize values in steps and checkpoints while working with your test.
    4. Also parametrize identification property values of test objects in the object repository using repository parameters.

QTP : Actions

A test can be divided in to actions to streamline the process of testing your application. Actions divide tests in to logical units.The actions used in the test and the order in which they are run, are displayed in the test flow pane. Test can be divided in to multiple actions by:
  • Creating new actions and inserting calls to them.
  • Inserting calls to existing actions.
  • Splitting existing actions.

Types of Actions
There are three kinds of actions:
  1. Reusable action: An action that can be called multiple times by the test with which it is stored as well as by other tests.
  2. Non-reusable action: An action that can be called only once in the test with which it is stored, and cannot be used by other tests.
  3. External action: A reusable action stored with test. External actions are read-only in the calling test, but you can choose to use a local , editable copy of the Data Table information for the external action.
Creating New Action
  1. if you want to insert a call to the new action from an existing action in your test, click the step after which you want to insert the new action.
  2. Select Insert>Call to New Action or click the Insert Call to New Action button on the Insert toolbar. The Insert Call to New Action dialog box opens.
                       
  3. In the Name box, type a new action name or accept the default name.
  4. In the Description box, add a description of the action. You can  also add an action description at a later time using the Action Properties dialog box.
  5. Ensure Reusable Action is selected if you want  to be able  to call the action from other tests or multiple times from within this test. By default this option is selected.
  6. Decide where to insert the call to the action by selecting At the end of the test or After the current step.
  7. Click OK. A new action is stored in your test.
Splitting Actions
You can split an action into two sibling actions or in to parent child nested actions. When you split an action in your test that uses a local object repository. The two actions have identical local  object repositories containing all of the objects that were in the original local object repository.

Steps to split an action
  1. Select the step before which you want the new action to begin.
  2. Select  Edit>Action>Split Action. the Split Action dialog box opens as shown below:

             
  3. Select one of the following options:
    • Independent of each other: splits the selected action in to two sibling actions.
    • Nested: Split the action in to Parent Child action. By nesting actions you can maintain the modularity of your test.
  4. If you want, modify the name and description of the two actions, use the Name and Description boxes.
Inserting calls to Actions
Steps to call the Copy of Action in your test:
  1. While recording or editing your test, choose Insert>Call to Copy of Action. The Select Action dialog box opens.
                           
  2. Use the From test browse button to select the test.
  3. Use the Action drop down to select a reusable action.
  4. Decide where to insert the call to the copy of the action and select At the end of the test or After the current step.
  5. Click OK. The action is inserted into the test as a copy of the action.
Inserting Call to an Existing Action
Steps to insert a call to an existing Action:
  1. Choose Insert>Call to Existing Action. The select action dialog opens.
                
  2. Use the From test browser button to find the test that contains the action you want to call. The Action box displays all reusable actions in the test you selected.
  3. Use the Action drop down to select a reusable action.
  4. Decide where to insert the call to the copy of the Action and select At the end of the Test or After the current step.
  5. Click OK. A call to the Action is inserted in the test flow.






















QTP : Output Values

An output value step is a step in which one or more values are captured at a specific point in your test and stored for the duration of the run session. the values can later be used as input at a different point in the test run.
You can output a value to:
  1. A test or action parameter
  2. The run time data table
  3. An environment variable
Design Time Data Table
The data table which is present in QTP before running the script is called Design Time Data Table. This contains various data to be used in the script while script is under execution.


Run Time Data Table
This is the data table you see while QTP script is under execution. At the starting of the script execution QTP copies the data from Design Time Data Table to Runtime Data Table and add, delete or change the data in the Run Time Data Table during script execution. At the end of script execution QTP exports the Runtime Data Table to the Test Results Sheet.

Why Run Time Data Table

If QTP directly modifies data in the DTD  table then we cannot use same data table for the next execution of the script since the data has been modified from initial execution. hence to ensure that the same script can be executed  without modifying the data in the data table. QTP does changes to the data only in Run Time Data Table without affecting the Run Time Data Table.

Using QTP you can create the folowing categories of output values:
  • Standard Output values
  • Text and Text Area Output Values
  • Database Output Values
  • XML Output Values
Standard Output Values
We can use standard output values to output the property values of most objects. For example after reserving a ticket, it must be confirmed. In this case confirming the ticket number is required which is generated during run time. you could create an outpuut value in your test to store the ticket number after it is generated during run time. Steps to create standard output value:
  1. Select Insert>Output Value>Standard Output Value.
  2. Click the object for which output value must be generated.
  3. In the Object Selection dialog box, select the object for which you want to specify an output value, and click OK. The output value properties dialog box opens for the selected object.
  4. Speccify the property value and their settings.
  5. When you finish defining the output value details , click OK. QTP inserts an output value step in your test.
Text Output Values We can create a text output value from a text string displayed on the screen, we can define the output value as part of the displayed text and you can specify the text before or after the output text.
Steps to create a text output value while recording :
  1. Select Test>Record.
  2. Choose Insert>Output Value>Text output Value.
  3. Click the text string for which you want to specify a text output value.
  4. Select the object for which you want to specify a text output value and click OK.
  5. The Text Output Value Properties dialog box opens.
  6. Specify the setting for the output value.
  7. when you have finished  defining the text output value details, click OK. QTP inserts an output value step in the test.
Database Output Values
you can use the database output values to output the value of the contents of database cell.

Steps to create database output values
  1. Select Insert>Output value>Database Output value.
  2. Use the wizard to define the query to retrieve the data that you want to output.
  3. Specify the values to output and their settings.
  4. When you have finished defining the output value details, Click OK. QTP inserts an output value step in your script.
XML Values Output
You can create XML output values from any XML document contained in an XML Web page or frame, or directly from an XML file. you can output element and/or attribute values in an XML output value step.
Steps to create XML output values from XML file:
  1. Select Insert>Output Value>XML Output Value.
  2. In the XML file box , enter the path of the XML file.
  3. Click OK. The XML Output Value Properties Dialog box opens.
  4. Specify the values to output.
  5. Click OK, QTP inserts n Output value step in your test.




Monday, January 9, 2012

QTP : Synchronisation


Sometimes scripts fail when they are run because of the speed mismatch between QTP and the application. QTP is always faster than the application as a result, the application responds to QTP slower than expected and the test fails. Instances where the application responds slower than expected and the test fails. These speed mismatch problems can be handled by synchronising the test. Synchronising the test involves making the QTP wait until the application is ready for performing the next step.

Synchronising the Test

By modifying the default time settings for a test in QTP. QTP provides some setting for the test which makes QTP to wait for the mentioned time in the setting.
  1. Browser Navigation Timeout: This setting makes QTP wait for the web page to load completely for the specified amount of time. By default the maximum wait time specified by QTP is 60 seconds. This setting can further be modified bythe user based on his requirement. This setting is found in File>settings>Web>Browser navigation timeout. This setting is applicable only for web applications.
  2. Object synchronization timeout: This setting makes QTP wait for the specified amount of time for the objects to appear. By default the time setting is 20 seconds which can be modified by the user. these settings can be found in File>Setting>Run>Object synchronization timeout.
Wait/Exist statements
These statements can be inserted to make QTP wait until an object exists.
Wait statement: When a wait statement is encountered, QTP pauses its script execution  for the specified amount of time. Once the specified amount is lapsed, QTP proceeds with the execution of next step.
Syntax: wait(n), where n is the number of seconds.

Exist statement: When a exist statement is inserted it checks if the object exists or not  in the application under test and returns a Boolean value for the same. Based on the return value, appropriated steps can be taken to handle the timing mismatch.You can combine wait and exist statements within a loop to instruct QTP to wait until the objects exists before continuing with the test.

Inserting Synchronization Point

A synchronization point can be inserted which makes QTP pause the test until an object property achieves a specified value. Synchronization point is often referred to as intelligent wait statement. Steps to insert a synchronization point are given below:
  1. Start a recording session. Select Insert>Synchronization Point.
  2. Click the object in your application for which you want to insert a synchronization point.
  3. Select the object for which you want to insert a synchronization point and click OK.

                     
  4. The Add Synchronization Point dialog box opens as shown in figure below:

                     
    The property name contains the list of properties of the object, property value is the value for which QTP should wait before continuing to the next step in the test. Timeout specifies the maximum amount of time to wait for the specified property to be achieved.
  5. Enter all the required values in Add Synchronization Point dialog and click OK. A WaitProperty step is added to the Test.




    Regular Expressions

    A regular expression is a special text string for describing a search for describing a search pattern. You can think of a regular expression as a wild card.You are probably familiar with wild card notations such as *.doc to find all word files in a file manager.

     Regular Expression Characters:

    Grouping Regular ExpressionsMultiple Regular Expressions Characters can be combined in a Single Expression. For example :
    Window("text:= .*(Report|Graph)").Close
    The above line closes a window with Text Report or Graph preceded by any set of alphanumeric characters.
    Using  the Backlash Character( \ )
    The backlash can be used along with a Regular Expression Character to indicate that the next character be treated as a literal character. ex:-
    Browser("Yahoo").Page("Yahoo").Link("text:= .*\..*").Click
    Here the backlash is preceded by the .(period) so the .(period) will be considered literal & not a Regular Expression.

    Regexp Object
    You can use regular expressions in VBScript by creating one or more instances of the RegExp object. This object allows you to find regular expression matches in strings, and replace regexp matches in strings with other strings. You can create this object in scripting as shown below:
    Regexp Rx = New Regexp

    REGULAR EXPRESSION EXAMPLE

    1. Matching Alphanumeric String
      [a-zA-Z0-9]+
      Description: Matches any alphanumeric string without any spaces.
      Matching Text : 9c, XYZ , B6H8
      Non Matching Text: 14.5
    2. Matching an Email Address
      (\w+)\.(w+)@(\w+)\.[A-Za-z]{2,4}
      Description: Matches any email ids in the format firstname.lastname@company.com
      (\w+) - Matches any Firstname with any alphanumeric characters & Underscore
      \. - Treat dot as a literal character. Slash(\) is an escape character which escapes the special meaning 
           of dot(.)
      (w+) - Matches any lastname with any Alphanumeric character & Underscore
      @ - Email id henceforth should be followed by @
      (\w+) - Matches any company name with any Alphanumeric characters & underscore
      \. - Company name followed by a dot
      [A-Za-z] {2,4}  - Matches alphabets of both lower case and uppercase. Number of characters can range from two to four.

      Matching Text : dce3062@gmail..com
      Non Matching Text: dce3062@gmail.xyzab
    3. Matching Credit Card
      ([4]{1})([0-9]{12-15})
      Description: The above expression validates against a visa card number. Here all visa card numbers should start with a digit 4 and are followed by numbers ranging from 12 to 15 numbers.
      Matching Text: 418563256985214 , 4125632569856321
      Non Matching Text: 
      3125652365214 : Here the first digit is not 4 hence the string is not matched

    Programming with VBScript

    VBScript stands for Visual Basic scripting. This scripting language was launched by Microsoft in 1996. Initially this scripting language was developed targeting web developers. Over these years VBScript has advanced itself into many versions evolving itself into a strong language for Automation tools.

    DATA TYPES
    VBScript has only one data type called a Variant. A Variant is a special type of data that can contain different kinds of information, depending upon how it is used.  A Variant can contain either numeric or string information, It behaves as a number when you use it in a numeric context, that is, when you do not include the value within double quotes, and as a string when you use it in a string context, that is , when you include the value in double quotes.You can just put the kind of data you want in a Variant, and the Variant behaves in a way that is most appropriate for the data that it contains.These different categories of information that can be contained in a Variant are called subtypes.The following table shows the subtypes of data that a Variant can contain:

    You can use conversion functions to convert data from one subtype to another. Ex: CBool, Cbyte,CInt etc.
    The VarType and Typename functions can be used to identify the data types  of a variable.
    Syntax: VarType(variable name)
                TypeName(variable name)
    The VarType and TypeName functions can return one of the following values:
    If the variable is an Array than VarType() returns 8192 + VarType(array_element). Example: for an array of integer VarType() will return 8192+2 = 8194.

    Comments
    Comments are the non executable lines of a script, comments are used in the script for better readability and maintenance. In VBScript comments can be provided in two ways.
    Use '(Single Quotes) or REM

    Variables
    A variable is a convenient placeholder that refers to a computer memory location where you can store program information that may change during the time your script is running. There are two ways you can declare your variables:

    1. Explicit declaration: You can declare variables explicitly in your script using:

      • DIM : Variables declared with DIM at the script level are available to all procedures within the script. You can declare variables by separating each variable name with a comma.
        ex- Dim a , b ,c.At the procedure level, variables are available only within the procedure.
      • Public : Variables declared using Public statement are available to all the procedures in all scripts of all projects.
      • Private: Private variables are available only to the script in which they are declared.
       
    2. Implicit declaration: You can also declare a variable implicitly by simply using its name in your script. In this method directly the name of the variable is used  and a value is assigned to a variable whenever required. Formal declaration of variables is not done here.
    Constants 
    The values that do not alter during the entire execution of the program are called as constants. These fixed values are defined in the script using the Const statement. ex- Const myname= " Armani "

    Naming Restrictions
    Variables names follow the standard rules for naming anything in VBScript. A variable name:
    • Must begin with alphabetic character.
    • Cannot contain a period.
    • Must not exceed 255 characters.
    • Must be unique in the scope in which it is declared.
    Operators:
    VBScript has a full range of operators, including arithmetic operators, comparison operators, concatenation
    operators and Logical operators. When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence. you can use parenthesis to override the order of precedence and force some parts of an expression to be evaluated before others. Operations within
    parenthesis are always performed before those outside. Within parentheses, however , standard operator precedence is maintained.

    When expression contain operators from more than one category, arithmetic operators are evaluated first, comparison operators are evaluated next and logical operators are evaluated last. Comparison operators all
    have equal precedence, that is, they are evaluated in the left to right order in which they appear. Arithmetic
    and Logical operators are evaluated in the following order of precedence

                                                                                                                                                    


    Conditional Statements
    Conditional statements are used to control the flow of the program. These statements in the program are
        executed when certain condition is true. In VBScript we have four conditional statements:
    •     If statement: Using If statement we can execute a single or block of statements when a condition 
          is true. Ex:- 
                                       If  i=0 Then
                                           msgbox "Hello" 
                                               i=i+1 
                                       End If
    • If then else: Using the conditional statement block of statements are executed. If the condition is true else alternate block of statements are executed if the condition is false. Example:-
      you want to execute a statement if a condition is true and execute another statement if the condition is not true, You must add the "Else" keyword.
                               
                               If  i=0 Then
                                           Print "Condition is True"
                                           msgbox "Hello" 
                                   Else
                                        Print " condition is false"
                                       msgbox " Good Bye"
                               End If
         
    • Select Case Statement: Using this statement one of several groups of statements are executed based on the expression value. Example: You can use the SELECT statement if you want to select one of many blocks of code to execute.

      Select case payment
          Case " Cash "
          msgbox " You are going to pay cash "
         Case " Visa "
         msgbox " You are going to pay with Visa "
         Case " AmEx"
         msgbox " You are going to pay with American Express"
         Case Else
         msgbox " Unknown method of payment"
      End Select
                        
    Looping statementsUsing looping statements a group of statements can be executed repeatedly. Loops are used when a statement or set of statements are to be executed repeatedly.
    1. For Loop: A For loop is used for situations when you need to do something over and over again until some condition statement fails. Ex:-

      For count=0 to 3
             Print (count)
      Next
       
    2. For Each Loop: It is useful when you want to go through every element in an array but you do not   know how many elements are there inside the array.Ex:-

      Dim a(2)
      a(0)= " Pen "
      a(1) =" Register" 
      a(2)= " Copy"
      For Each item In a
         Print(item)
      Next
    3. While Loop: A While Loop is a simple loop that keeps looping while something is true. Ex:-
      Dim counter
      counter =10
      While counter>0
         print (counter)
         counter = counter -1
      Wend
    4. Do Loop: Do Loop is used when we do not know how many repetitions you want. The block of code is repeated while a condition is true or until a condition becomes true. Ex:-

      Do While i>10
      Print(i)
      Loop

      You can use the Until keyword to check a condition in a Do Loop statement.
      Do Until i=10
       Print (i)
      Loop

      If i equals 10, the code inside the loop will never be executed.

      Do
         Print(i)
      Loop Until i=10


      The code inside this loop will be executed at least one time, even if i=10.
    PROCEDURES: 
    Procedures are a set of statements that are enclosed within a group. This group of statements perform a specific task. Once a procedure is defined it can be called from different locations in the programs as many times as required by the program. The main purpose of using procedure is to maintain modularity and re usability. In VBScript there are two types of procedures, the Sub procedure and the Function procedure.
    Advantages of procedures:
    • Modularity: By dividing our scripts into procedures we can maintain and write programs by segregating the code into smaller and manageable blocks.
    • Reusable: Procedures help us to reduce the number of lines of the code by reusing the code.
    • Generalization: Once a procedure is defined it can be used by different tests.
    • Recursive: Procedures can call themselves any number of times.
    Sub Procedures:  Sub procedure is a series of VBScript statements, enclosed by Sub and End Sub statements. The Sub procedure do not return any value.Procedures use two built-in function. MsgBox and InputBox, to prompt a user for some information. It then displays the results of  a calculation based on that information. Ex:-
       Sub convertTEMP()
           temp= InputBox("Please enter the temperature in degree F",1)
          MsgBox " The temperature is " &Celsius(temp) & "degrees C"
      End Sub

    Function Procedures: A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements. A Function Procedure is similar to to a Sub procedure but the only difference is that it can also return a value. A Function returns a value by assigning a value to its name. The return type of a Function is always a Variant.Ex:-

    Function Celsius(fDegrees)
           Celsius= (fDegrees - 32) * 5/9
    End Function




    Scope of Procedures:
    A Procedure can be scoped as private,public or default. Procedures are public by default.
    • Public: Indicates that the procedure is accessible to all other procedures in all scripts.
    • Private: indicates that the procedure is accessible only to other procedures within the script where it is declared.
    • Default: Used only with public keyword in a class block to indicate that the Function procedure is the default method for the class. An error occurs if more than Default procedure is specified in a class.
    Call Statement
    Call Statement is used to pas program execution control to procedure. Procedure can be called without using a call statement. In such scenarios whenever the program encounters a procedure name it will automatically pass control to the procedure. However , if you use the Call keyword to call a procedure that requires arguments, argument list must be enclosed in parentheses. if you omit the Call keyword from the procedure call, you must also omit the parentheses around argument list. example:-
    Call MyProc() or MyProc

    Exit Statement
    The code within a procedure is executed until the last line of the procedure i.e. End statement is encountered. In instances where the user wants to exit the procedure when certain conditions are met, exit statements come into use. Exit statements when encountered within a procedure body exits the procedure unconditionally.
    Syntax: Exit [Procedure]


    BUILT-IN FUNCTION LIBRARY
    VBScript has many built-in functions that can be used to enhance the speed of development.
    • Conversion Functions
    • String Functions
    • Array Functions
    • Date and Time Functions
    • Math Functions
    • Other Functions
     CONVERSION FUNCTIONS

    STRING FUNCTIONS


    ARRAY FUNCTIONS



    DATE & TIME


    MATH  FUNCTIONS

    OTHER FUNCTIONS




    VBScripting Examples

    A) Write a program to find out whether the given number is Even number or Odd number?

    1. Dim num
    2. num=inputbox ("Enter a number")
    3. n = cint(n) 
    4. If num mod 2=0 Then
    5. msgbox "This is a Even Number"
    6. Else
    7. msgbox "This is a Odd Number"
    8. End If
    Line 1: Declare variable n.
    Line 2: Displays dialog box for the user to input text , returns a string value.
    Line 3: Converts input expression into an Integer and assigns that value to n.
    Line 4: If the number is divided by 2 then number is an even number else it is an odd number.
    Line 5: Prints if the number is an Even number
    Line 7: Prints if the number is an Odd number.
    Line 8: End of If statement.

    Output:



     
    B) Find the factorial of a given number.
    1. Dim N,factorial
    2. N = inputbox(" Enter the Number")
    3. N = Cint(N)
    4. duplicateNumber = N
    5. factorial = 1
    6. if N<0 Then
    7. Msgbox  (" No factorial for Negative Numbers ")
    8. elseif (N=0) or (N=1) then
    9. Msgbox (" Factorial of  " &cstr(N) + " is 1")
    10. else
    11. while N>1
    12. factorial = factorial * N
    13. N = N-1
    14. Wend
    15. Msgbox(" Factorial of " & CStr(duplicateNumber) & " is " & CStr(factorial))
    16. end if
    Line 1-5: Variable declaration, assignment and Input Reading
    Line 6-7: If the Number entered is a negative number then no factorial
    Line 8-9: If the Number entered is 0 or 1 then factorial value is 1
    Line10-13: If N>1 then factorial = factorial times N (factorial = factorial * N)
    Line 15: Prints the factorial value

    For input value = 5
    Iteration                                  Value of N                                  Factorial
    1                                                    5                                            1*5
    2                                                    4                                            1*5*4
    3                                                    3                                            1*5*4*3
    4                                                    2                                            1*5*4*3*2


    Output: Factorial of 5 is 120

                 



    C) Verify whether the given two Strings are equal.

    1. Dim string1,string2 
    2. string1 = inputbox (" enter the first string ")
    3. string2 = inputbox (" enter the second string ")
    4. MsgBox(" First string is :" +string1)
    5. MsgBox(" Second string is :" +string2)
    6. if StrComp(string1,string2) = 0 Then
    7. MsgBox ( " The Strings are Equal ")
    8. else
    9. MsgBox(" The strings are not Equal ")
    10. End if
    Line 1: Declaration of variables
    Line 2-3: Initialises the String
    Line 4-5: Displays the given two strings
    Line 6: StrComp function compares the given two strings. if the two strings are the same the StrComp function returns 0.

    Input:
                        
                    
                         

    Output: