Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compare strings and perform action
#1
Wink 
Hi All,

In run time, I want to compare strings in the datatable and perform action.

I have attached the screenshot with the code and datatable in the post.

Am also posting code here:
Code:
Invokeapplication ("E:\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe") Dim a, b row=DataTable.GetCurrentRow a=datatable("A", dtGlobalSheet) DataTable.SetCurrentRow(row+1) b=datatable("A", dtGlobalSheet) If strcomp(a,b)=0 Then Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set "Forrest" Dialog("Login").WinButton("Cancel").Click Else Dialog("Login").Activate Dialog("Login").WinEdit("Password:").SetSecure "4e6224718ae0eaf92a4e26655f509650a67f9999" Dialog("Login").WinButton("Cancel").Click End If

Aim: If Column "A" has value "ABC" then QTP must Enter Username and click cancel.

If column "A" has value "DEF" then QTP must enter password and click cancel.

But according to my code, it is entering Username if strings are same irrespective of data in Column "A".

Help me with the logic and also on coding if possible.

One of my application runs in similar logic so for better understanding I took Flight Application as example.

In my application, I have two Pages:
1. Change Organization (Enter Organization Name i.e column "A" values)
2. Enter values for organization

I will enter organization name (one orgnization name) once and then will enter its related data (this will be multiple records).
Then will again change Organization name and enter its records.

First column will have organization name; similar to the one I posted here i.e in Page1.
For Example: If Organization name is "ABC", then QTP must enter data related to column "ABC"

If value in Column "A" is changed from "ABC" to other value, say "DEF", then QTP must enter "DEF" in Organization name (i.e., Page1 in my application) and enter data related to column "DEF" (These data will be entered in Page2 of my application)

FYI: This action is no way related to my previous posts.

Thanks in advance
- Gump


Attached Files
.doc   screen.doc (Size: 97.5 KB / Downloads: 211)
Reply
#2
Hi Gump,

As per my understanding of the explantion u have given, i must say its better for you to compare the each cell value..

Ur code shld be something like this...
Code:
a=datatable("A", dtGlobalSheet) if a="ABC" Then Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set "ABC" Dialog("Login").WinButton("Cancel").Click ElseIf a="DEF" Then Dialog("Login").Activate Dialog("Login").WinEdit("Password:").SetSecure "4e6224718ae0eaf92a4e26655f509650a67f9999" Dialog("Login").WinButton("Cancel").Click End If

i hope this will work. Smile

The problem with ur code is that it is not checking for a specific value, it is comparing two strings instead. So whatever the values are in the datatable, if the two rows values are equal, it will enter the userID always.

Do let me know if u need further informaton.

Regards,
Ankesh
Reply
#3
Hi Ankesh,

Thanks for replying. Am glad that my query is answered after these many days.

You understood the problem correctly but not exact way.

Code:
As per my understanding of the explantion u have given, i must say its better for you to compare the each cell value.. Ur code shld be something like this... a=datatable("A", dtGlobalSheet) if a="ABC" Then
If I had to assign the values "ABC" or "DEF", it takes more time for me to do that manually and also the data I get is huge. Thats the reason I want QTP to take care of this and automate it completely as I dont want manual work to be done.

FYI: In my datatable the values such as "ABC" or "DEF" itself will be more than 1000 numbers. If I had to go by your method then I just have to enter those values manually 1000 times to assign it to a variable.
I hope you understand what am trying to say.

Please do guide me in automating this.

Thanks and Regards,
- Gump
Reply
#4
Hi Gump,
As per my understanding your query the below code will solve your problem.

(Before that you have to change settings in File ->Settings->Run->Check Run One Iteration Only)
Code:
'Count all rows in Global datatable iCount = DataTable.GetRowCount msgbox iCount For i = 1 to iCount InvokeApplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe" cData = DataTable.Value("A","Global") msgbox cData If Strcomp(cData,"ABC") = 0 Then Dialog("Login").WinEdit("Agent Name:").Set "Suresh" Dialog("Login").WinButton("Cancel").Click else Dialog("Login").WinEdit("Password:").Setsecure "4e65b185ba904947d41d711097890e962b647446" Dialog("Login").WinButton("Cancel").Click End If DataTable.SetNextRow Next
Reply
#5
Hi gump,
here in your case we are taking values from data table and performing actions according to the condition, what the answer given by ankesh is correct, in order to save time you could use select statement.

example
Code:
a=datatable("A", dtGlobalSheet) Select Case a Case "ABC" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set "ABC" Dialog("Login").WinButton("Cancel").Click Case "DEF" Dialog("Login").Activate Dialog("Login").WinEdit("Password:").SetSecure "4e6224718ae0eaf92a4e26655f509650a67f9999" Dialog("Login").WinButton("Cancel").Click Case else next action End Select
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare WebTable Elements saraiado 1 2,984 06-11-2015, 06:54 PM
Last Post: venkatesh9032
  How to compare two binary values Naresh 0 2,692 09-09-2014, 05:06 PM
Last Post: Naresh
  Same command needs to be performed twice to actually perform it pistaa 2 3,535 04-25-2014, 01:26 PM
Last Post: pistaa
  Perform some functions whenever QTP Stop button is pressed smartkarthi 2 3,798 08-22-2013, 11:43 AM
Last Post: smartkarthi
  how to compare excel with datatatble diya 4 6,260 12-04-2012, 05:39 AM
Last Post: diya

Forum Jump:


Users browsing this thread: 1 Guest(s)