Micro Focus QTP (UFT) Forums
Query - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Query (/Thread-Query--3856)



Query - indranilgoswamimcb - 10-05-2010

I have the following query:

Block of code:
{
statement 1
statement 2
"
"
"
}

if ....exist
execute the block of code again

How do I implement this in QTP? the block of code should be executed only once and again if the if condition becomes true.


RE: Query - KavitaPriyaCR - 10-05-2010

Hi, If you want the block to be executed till the xyz.Exists...then i think it can be done in this way:
Code:
If (xyz.exists(0)) Then
  Do While (xyz.Exists(0))
    Block of code:
    {
     statement 1
     statement 2
     "
     "
     "
     }
   Loop
End If



RE: Query - sreekanth chilam - 10-05-2010

Hi,

Here comes the concept of "Reusablity" into the picture.

Your 'block of code' by nature is reusable since it has to be called & executed whenever required condition become true.

So the block of statements should be converted to any one of below and called wherever applicable.

1. Userdefined Function
2. Reusable Action


RE: Query - quicktest - 10-06-2010

I would suggest you to write the block of code in a flat file like .vbs file in a function and call the function whenever required.


RE: Query - KavitaPriyaCR - 10-06-2010

Yes as Sreekanth said, If u want the script to be executed once and on some conditions, you can call user defined function as:
Write the block of code in text file, save as xyz.vbs, add it in settings and call it inside If statement as:
If (Condition) Then
Call xyz()
End If

OR

Write the block in reusable "action2" and run that action inside the main action
If (Condition) Then
RunAction "Action2", oneIteration
End If