jmp Posted October 28, 2019 Share Posted October 28, 2019 I am trying to verify my customer using this code : #include <IE.au3> $oIE = _IEAttach ("My Webpage") _IELoadWait($oIE) $btnSelect = _IEGetObjById($oIE,"btnselect") _IEAction($btnSelect,"click") $btnsubmit = _IEGetObjById($oIE,"btnsubmit") _IEAction($btnsubmit,"click") while 1 _IELoadWait($oIE) $body = _IEBodyReadHTML($oIE) If StringInStr($body, "Verify Member") Then $btnverify = _IEGetObjById($oIE,"btnverify") _IEAction($btnverify,"click") _IELoadWait($oIE) $memberconsent = _IEGetObjById($oIE,"memberconsent") _IEAction($memberconsent,"click") _IELoadWait($oIE) $imgverify = _IEGetObjById($oIE,"imgverify") _IEAction($imgverify,"click") EndIf If StringInStr($body, "Verification Failed") Then ContinueLoop Else $btnmeselect = _IEGetObjById($oIE,"btnmeselect") _IEAction($btnmeselect,"click") _IELoadWait($oIE) exitloop EndIf WEnd But i want to count number of times an error showing about verification failed. If verification failed more than 3 times then i want to exit my script. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 28, 2019 Share Posted October 28, 2019 @jmp Adjust your While loop with something like this: Global $intCounter = 0 While $intCounter < 3 If Condition Then $intCounter += 1 Else ; Something else EndIf WEnd Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
jmp Posted October 28, 2019 Author Share Posted October 28, 2019 3 hours ago, FrancescoDiMuro said: @jmp Adjust your While loop with something like this: Global $intCounter = 0 While $intCounter < 3 If Condition Then $intCounter += 1 Else ; Something else EndIf WEnd @FrancescoDiMuro How can i put my code in this? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 28, 2019 Share Posted October 28, 2019 @jmp Instead of using While 1, use the While in the last post. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Musashi Posted October 28, 2019 Share Posted October 28, 2019 11 minutes ago, jmp said: How can i put my code in this? #include <IE.au3> $oIE = _IEAttach("My Webpage") _IELoadWait($oIE) $btnSelect = _IEGetObjById($oIE, "btnselect") _IEAction($btnSelect, "click") $btnsubmit = _IEGetObjById($oIE, "btnsubmit") _IEAction($btnsubmit, "click") Global $iErrorCounter = 0 While $iErrorCounter < 3 _IELoadWait($oIE) $body = _IEBodyReadHTML($oIE) If StringInStr($body, "Verify Member") Then $btnverify = _IEGetObjById($oIE, "btnverify") _IEAction($btnverify, "click") _IELoadWait($oIE) $memberconsent = _IEGetObjById($oIE, "memberconsent") _IEAction($memberconsent, "click") _IELoadWait($oIE) $imgverify = _IEGetObjById($oIE, "imgverify") _IEAction($imgverify, "click") EndIf If StringInStr($body, "Verification Failed") Then $iErrorCounter += 1 Else $btnmeselect = _IEGetObjById($oIE, "btnmeselect") _IEAction($btnmeselect, "click") _IELoadWait($oIE) ExitLoop EndIf WEnd "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
jmp Posted October 28, 2019 Author Share Posted October 28, 2019 (edited) 4 hours ago, Musashi said: #include <IE.au3> $oIE = _IEAttach("My Webpage") _IELoadWait($oIE) $btnSelect = _IEGetObjById($oIE, "btnselect") _IEAction($btnSelect, "click") $btnsubmit = _IEGetObjById($oIE, "btnsubmit") _IEAction($btnsubmit, "click") Global $iErrorCounter = 0 While $iErrorCounter < 3 _IELoadWait($oIE) $body = _IEBodyReadHTML($oIE) If StringInStr($body, "Verify Member") Then $btnverify = _IEGetObjById($oIE, "btnverify") _IEAction($btnverify, "click") _IELoadWait($oIE) $memberconsent = _IEGetObjById($oIE, "memberconsent") _IEAction($memberconsent, "click") _IELoadWait($oIE) $imgverify = _IEGetObjById($oIE, "imgverify") _IEAction($imgverify, "click") EndIf If StringInStr($body, "Verification Failed") Then $iErrorCounter += 1 Else $btnmeselect = _IEGetObjById($oIE, "btnmeselect") _IEAction($btnmeselect, "click") _IELoadWait($oIE) ExitLoop EndIf WEnd @Musashi Can i get msgbox after error showed three times ? i want to also add some code If verification failed 3 times. Edited October 28, 2019 by jmp add some code If verification failed 3 times Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 28, 2019 Share Posted October 28, 2019 @jmp What's wrong with opening the Help file and do the simple tasks you are asking for yourself? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
jmp Posted October 28, 2019 Author Share Posted October 28, 2019 (edited) 15 minutes ago, FrancescoDiMuro said: @jmp What's wrong with opening the Help file and do the simple tasks you are asking for yourself? @FrancescoDiMuro i am added line like this : #include <IE.au3> $oIE = _IEAttach("My Webpage") _IELoadWait($oIE) $btnSelect = _IEGetObjById($oIE, "btnselect") _IEAction($btnSelect, "click") $btnsubmit = _IEGetObjById($oIE, "btnsubmit") _IEAction($btnsubmit, "click") Global $iErrorCounter = 0 While $iErrorCounter < 3 _IELoadWait($oIE) $body = _IEBodyReadHTML($oIE) If StringInStr($body, "Verify Member") Then $btnverify = _IEGetObjById($oIE, "btnverify") _IEAction($btnverify, "click") _IELoadWait($oIE) $memberconsent = _IEGetObjById($oIE, "memberconsent") _IEAction($memberconsent, "click") _IELoadWait($oIE) $imgverify = _IEGetObjById($oIE, "imgverify") _IEAction($imgverify, "click") EndIf If StringInStr($body, "Verification Failed") Then $iErrorCounter += 1 elseif $iErrorCounter = 3 then msgbox(0, "", "Limit exceeded") ;something here Else $btnmeselect = _IEGetObjById($oIE, "btnmeselect") _IEAction($btnmeselect, "click") _IELoadWait($oIE) ExitLoop EndIf WEnd But i am not getting msgbox Edited October 28, 2019 by jmp Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 28, 2019 Share Posted October 28, 2019 @jmp That's because that line of code is not executed, 'cause of the While condition, which loops until that variabile is less than 3, and then exit, so, put that if outside the While loop (after the WEnd). Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Musashi Posted October 28, 2019 Share Posted October 28, 2019 Sometimes it is helpful to reduce the code to the process logic, as @FrancescoDiMuro has already suggested : Global $iErrorCounter = 0 Global $bErrorCondition = False ; *** For this simulation only While $iErrorCounter < 3 ConsoleWrite('> ==> LOOP : $iErrorCounter = ' & $iErrorCounter & @CRLF) ; [CODE...] $bErrorCondition = True ; Simulates --> Verification Failed If $bErrorCondition Then $iErrorCounter += 1 ConsoleWrite('! $iErrorCounter + 1 : $iErrorCounter = ' & $iErrorCounter & @CRLF) Else ; Less than 3 Errors : ; [CODE...] ExitLoop EndIf WEnd if $iErrorCounter = 3 Then MsgBox(0, 'Error : ', 'Limit of three errors reached') ; Insert additional code here EndIf FrancescoDiMuro 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
jmp Posted October 29, 2019 Author Share Posted October 29, 2019 (edited) 7 hours ago, Musashi said: Sometimes it is helpful to reduce the code to the process logic, as @FrancescoDiMuro has already suggested : Global $iErrorCounter = 0 Global $bErrorCondition = False ; *** For this simulation only While $iErrorCounter < 3 ConsoleWrite('> ==> LOOP : $iErrorCounter = ' & $iErrorCounter & @CRLF) ; [CODE...] $bErrorCondition = True ; Simulates --> Verification Failed If $bErrorCondition Then $iErrorCounter += 1 ConsoleWrite('! $iErrorCounter + 1 : $iErrorCounter = ' & $iErrorCounter & @CRLF) Else ; Less than 3 Errors : ; [CODE...] ExitLoop EndIf WEnd if $iErrorCounter = 3 Then MsgBox(0, 'Error : ', 'Limit of three errors reached') ; Insert additional code here EndIf @Musashi Why the code needs to be reduced ? As @FrancescoDiMuro has suggested, I have written the code for msgbox outside the while loop, and it was working for me. expandcollapse popup#include <IE.au3> $oIE = _IEAttach("My Webpage") _IELoadWait($oIE) $btnSelect = _IEGetObjById($oIE, "btnselect") _IEAction($btnSelect, "click") $btnsubmit = _IEGetObjById($oIE, "btnsubmit") _IEAction($btnsubmit, "click") Global $iErrorCounter = 0 While $iErrorCounter < 3 _IELoadWait($oIE) $body = _IEBodyReadHTML($oIE) If StringInStr($body, "Verify Member") Then $btnverify = _IEGetObjById($oIE, "btnverify") _IEAction($btnverify, "click") _IELoadWait($oIE) $memberconsent = _IEGetObjById($oIE, "memberconsent") _IEAction($memberconsent, "click") _IELoadWait($oIE) $imgverify = _IEGetObjById($oIE, "imgverify") _IEAction($imgverify, "click") EndIf If StringInStr($body, "Verification Failed") Then $iErrorCounter += 1 Else $btnmeselect = _IEGetObjById($oIE, "btnmeselect") _IEAction($btnmeselect, "click") _IELoadWait($oIE) ExitLoop EndIf WEnd If $iErrorCounter = 3 then msgbox(0, "", "Limit has been reached") ;something here Endif Edited October 29, 2019 by jmp Link to comment Share on other sites More sharing options...
Musashi Posted October 29, 2019 Share Posted October 29, 2019 (edited) 7 hours ago, jmp said: @Musashi Why the code needs to be reduced ? Your problem with the messagebox was easy to solve ( @FrancescoDiMuro told you what's to do ) Now imagine, you have a more complex, nested structure with various While.. , If...ElseIf...Else , Select...Case..., Switch... and so on. To analyze, whether these conditions are being executed or not, it is often easier to use the process logic without the complete additional code. In such cases reducing the code can serve the purpose of traceability. For troubleshooting, it's more of a downside to show a section with i.e. 100 lines, that will not be processed anyway. Use Consolewrites and replace required function results with dummies. Edited October 29, 2019 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now