If-Then-Else not working right in QTP

  • Questions
  • If-Then-Else not working right in QTP
Question ID: 105157
1
0

Case description:
IF ELSE statements not working correctly: See code following code example:

If testargs("LocDate") = "sysdate" Then

msgbox "LocDate = sysdate"

Set MyRecordSet14= DBO.Execute(" Update locdate set locdt = (SELECT TO_CHAR(SYSDATE) FROM dual) where locnbr = " & aa_Variable.Item("LocNbr") & "and locdtcd = ‘PRO"’)

DBO.Execute ("Delete from DaySumm where businessdt > (SELECT TO_CHAR(SYSDATE) FROM dual) and locnbr=" & aa_Variable.Item("LocNbr") & "")

DBO.Execute ("Delete from History where businessdt > (SELECT TO_CHAR(SYSDATE) FROM dual) and locnbr=" & aa_Variable.Item("LocNbr") & "")

Set MyRecordSet16= DBO.Execute("Update daysumm set busdt = (SELECT TO_CHAR(SYSDATE) FROM dual) where busdt=(select max(busdt) from daysumm where locnbr=" &aa_Variable.Item("LocNbr") & " )and locnbr=" & aa_Variable.Item("LocNbr") & "")
Set MyRecordSet17= DBO.Execute("Update history set busdt = (SELECT TO_CHAR(SYSDATE) FROM dual) ,eodldt = null,eodcdt = null,depcheckflg = ‘N’,rpdfltflg=’N’,pdldfltflg= ‘N’,rpachflg= ‘N’,csodefflg=’N’,csoachflg = ‘N’,csofchgflg=’N’ where busdt=(select max(busdt) from history where locnbr=" & aa_Variable.Item("LocNbr") & ") and locnbr= " & aa_Variable.Item("LocNbr") )

Else

msgbox "LocDate Not= sysdate"

BOTH msgboxes are being displayed???

Marked as spam
Posted by (Questions: 339, Answers: 20)
Asked on October 29, 2013 7:11 pm
6 views
Answers (1)
1
Private answer

If the If..Then...Else statement isn't working properly, and it's caused by a run-time error in the code.

In order to troubleshoot it, the If statement needs to be wrapped in error handling code.

If you do not know how to do this, here's a site that can help, and you can do a web search on VBScript Error Handling to find other sites that can help.
[http://blogs.msdn.com/b/ericlippert/archive/2004/08/19/error-handling-in-vbscript-part-one.aspx][1]

[1]: http://blogs.msdn.com/b/ericlippert/archive/2004/08/19/error-handling-in-vbscript-part-one.aspx

Marked as spam
Posted by (Questions: 16, Answers: 749)
Answered on October 29, 2013 7:12 pm
Yes, that is what was going on. Using the error handling code, we found our DB set up wasn't right!
( at October 29, 2013 7:14 pm)