• Conditional Statements VBScript | Automation Testing QTP/UFT

    Conditional Statements VBScript:

    Control statements are subdivided in to two types.

    1. Conditional Control Statements
    2. Looping Control Statements

    Here we are going to see Conditional Statements VBScript. In the next post we see about Looping Statements.

    CONDITIONAL STATEMENTS VBScript:

    Used to execute single statements or set of statements based on conditions.

    The following Conditional statements are available in VB Script:
    IF STATEMENT: executes a set of statement when a condition is true
    IF – ELSE STATEMENT: select one of two sets of statements to execute
    IF – ELSEIF STATEMENT: select one of many sets of statements to execute
    SELECT CASE STATEMENT: select one of many sets of statements to execute
    Let’s see the syntax of each condition with an example below:

    IF STATEMENT: (One conditional statement)

    To execute only one statement when a condition is true:

    SYNTAX:
    Example:
    There is no “Else” in the above example. It performs only one action when a condition is true

    IF – ELSE STATEMENT: (Two conditional statement)

    SYNTAX:
    Example:
    It is to execute more than one statement when a condition is true.

    IF – ELSEIF STATEMENT: (More than two conditional)

    SYNTAX:
    Example:

    SELECT CASE STATEMENT:

    It’s an alternative to IF-THEN-ELSE. It makes code more efficient and readable.

    SYNTAX:
    EXAMPLE:
    NOTE:
    In select case, the subdata type of “main expression” and “sub expression” should be same “same data type”
    Data will always compare with equal relationship operator
    Here the expressions are case sensitive. Eg: “Red” is not equal to “red”
    In the above example, we used string function (lcase) to convert the input value to lowercase

    VBScript Series:

    VBScript for Automation (QTP/UFT) Testing – Part 1

    VBScript for Automation (QTP/UFT) Testing – Part 2

    VBScript for Automation (QTP/UFT) Testing – Part 3

    VBScript for Automation (QTP/UFT) Testing – Part 4

    VBScript for Automation (QTP/UFT) Testing – Part 5

    Sharing is caring.

    Share on facebook
    Facebook
    Share on twitter
    Twitter
    Share on linkedin
    LinkedIn

    Like This Post?

    We have a lot more where that came from?

    We only send really good stuff occasionally, promise.

    Rajkumar SM

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Share on facebook
    Share on google
    Share on twitter
    Share on linkedin
    Share on whatsapp

    Recent Posts:

    Scroll to Top
    API Testing eBook

    DOWNLOAD FOR FREE