Automation testing QTP with VB Script functions Interview questions


Total available count: 68
Subject - Software Testing
Subsubject - Automation testing QTP with VB Script functions

For...Next Statement?

For...Next statement repeats a group of statements a specified number of times.

Syntax: 
For counter = start To end [Step step]
    [statements]
    [Exit For]
    [statements]
Next

Arguments:
counter: Numeric variable used as a loop counter. The variable can't be an array element or an element of a user-defined  type.
start: Initial value of counter.
end: Final value of counter.
step: Amount counter is changed each time through the loop. If not specified, step defaults to one.
statements: One or more statements between For and Next that are executed the specified number of times.

Example-1: 

'For...Next 
    Counter = 1
    For  Counter = 1 to 4
    Total =Inputbox("Please enter the total marks in numbers")                                      
If   Total < 50 Then             
        MsgBox  "Fail"                  
           ElseIf  Total >=50 and Total <=60   then                  
        Msgbox "Second Class"
  ElseIf  Total >60 and Total <80   then           
        Msgbox "First Class"
           ElseIf  Total >=80  then            
     Msgbox "Distinction"       
                 Else
    Msgbox "Invalid Marks"                   
                    End If
     Next

Example-2: 

' increment  loop by  3 
    Counter = 1
    Result  = 0
    For  Counter = 1 to 10  step 3 
    Result=Result + Counter
    Print Result
    Next
    

Example-3: 

'Decrement loop by  2 
    For  Counter = 10 to 1  step -2   
    Print Counter
    Next

Example-4: 

'Exit For Loop
For Counter=1 to 10
    If  Counter=6 Then
        Exit for
    End If
Print Counter
Next


 




Next 5 interview question(s)

1
For Each...Next Statement?
2
If...Then...Else Statement?
3
Select Case statement?
4
While...Wend statement?
5
With statement?

Comments