Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement
#1
Dear All,
I add this to my QTP scripts.
I don't know why the value the i would added up to 6 after the first iteration in the while loop.
I am really confused.
The value of i equal to 0 and after running in the first iteration in the while loop, it should become 1 instead of 6.

As I am now in QTP and VB, please help!


Code:
Dim i , field i = 0 field = "Basic Work Time" While i<6 SiebApplication("Siebel Energy (CMS DR)").SiebScreen("Appointment Booking").SiebView("TG Appointment Booking").SiebApplet("Audit Trail Items").SiebButton("Query").Click SiebApplication("Siebel Energy (CMS DR)").SiebScreen("Appointment Booking").SiebView("TG Appointment Booking").SiebApplet("Audit Trail Items").SiebText("Field").SetText field SiebApplication("Siebel Energy (CMS DR)").SiebScreen("Appointment Booking").SiebView("TG Appointment Booking").SiebApplet("Audit Trail Items").SiebButton("Go").Click If i = 0 Then i = 1 field = "Contractor Labour Rate" end if If i = 1 Then i = 2 field = "Quota" end if If i = 2 Then i = 3 field = "Message Print Location" end if If i = 3 Then i = 4 field = "Order Print Location" end if If i = 4 Then i = 5 field = "SAP Print Location" end if If i = 5 Then i = 6 field ="Store Location" end If Wend



Thanks
Jody
Reply
#2
this is because when the first if statement (i = 0) gets executed then you are assigning i = 1 so when control moves to next if statement then the condition is true as you value of i is now 1 nad you are assigning i =2, so when again control moves to next if statement then again it is true and its is again assigned to next if condition and so on. finally the first iteration ends up with a value of 6.

hope the cause of issue is clear to you now.

dont assign the value of i in a if statement if you need to check it again in your next statements
increment thevalue of i with i = i+1 just before 'wend'. or better use Select Case

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)