Jump to content
Sign in to follow this  
cyanidemonkey

Bubble up (Return) multiple Functions?

Recommended Posts

cyanidemonkey

Hi, I am writing code that has functions calling functions and them moving on to another function once done ie;

;psudo code
;call functions:
_FuncA()
_FuncB()

_FuncA()
   ; do stuff then call another func
   _FuncC()
EndFunc

_FuncB()
   ; do stuff that depends on _FuncC Returning sucess
EndFunc

_FuncC()
  ; do stuff, if fail stop script.
EndFunc

I am wondering if I can stop all scripts (not exit the app) if a result is bad rendering the remaining functions no longer required.

Can I bubble up function returns, or should I do this a different way?

Maybe Return a responce from FuncA or FuncC the wrap the call to FuncC in a If/EndIf?

Edited by cyanidemonkey

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites
computergroove

While 1

     _FuncA()

     _FuncC()

     _FuncB()

     _FuncC()

WEnd

If your code isnt too big and you want to share it I can make something that you can wrap your head around.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
computergroove

Tidy your code to make sense.

While 1
    _FuncA()
    _FuncC()
    _FuncB()
    _FuncC()
WEnd
  • Like 1

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
cyanidemonkey

Sorry guys, heres some code, a bit striped down to get to the point, but basically I want to call all the tests from the _runTest() function as I am planing to add the ability to turn on/off various tests to be ran in the test session.

The thing is if the first test fails, all others will fail due to no webpage to test links on, so I want to stop remaining tests, I wondered if I could bubble up and out of _runTest() from a nested function by Return Return or something.

;button calls this function
_runTests()

Func _runTests()
   $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")   ;required to test AJAX Modal pop ups and other 'dud' pages returned by server.
    _openWebsite()
    _checkLoginLinks(2)
    _checkLoginLinks(1)
EndFunc

Func _openWebsite()
   _appendLog(1,"Opening: " & $sFullDomain)
   $oIE = _IECreate($sFullDomain)
   _IELoadWait($oIE)
   If $oIE.document.title = "Skilitics - Log in" Then
      _logResult("PASS")
   Else
      _logResult("FAIL")
      _appendLog(1,"TESTS ABORTED!")
      _appendLog(2,"Could not connect to website. All other tests will fail as a result, the script has terminated. Please check the URL in Test Config and try again.")
   EndIf
EndFunc

Func _checkLoginLinks($iLink)
   _appendLog(1,"Link: " & $oIE.document.links($iLink).text)
   _appendLog(1,"Link URL: " & $oIE.document.links($iLink).href)
   Local $href = $oIE.document.links($iLink).href
   ;Click the link
   _IELinkClickByIndex($oIE,$iLink)
   ;get results, return pass/fail etc.....
EndFunc
Edited by cyanidemonkey

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites
Geir1983

Use the SetError() and Return statements?

;button calls this function
_runTests()

Func _runTests()
   $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")   ;required to test AJAX Modal pop ups and other 'dud' pages returned by server.
    _openWebsite()
    IF @error Then Return   ;If previous function returned an error stop executing this function
    _checkLoginLinks(2)
    _checkLoginLinks(1)
EndFunc

Func _openWebsite()
   _appendLog(1,"Opening: " & $sFullDomain)
   $oIE = _IECreate($sFullDomain)
   _IELoadWait($oIE)
   If $oIE.document.title = "Skilitics - Log in" Then
      _logResult("PASS")
   Else
      _logResult("FAIL")
      _appendLog(1,"TESTS ABORTED!")
      _appendLog(2,"Could not connect to website. All other tests will fail as a result, the script has terminated. Please check the URL in Test Config and try again.")
      SetError(1)   ;Set Error in your check functions
   EndIf
EndFunc

Func _checkLoginLinks($iLink)
   _appendLog(1,"Link: " & $oIE.document.links($iLink).text)
   _appendLog(1,"Link URL: " & $oIE.document.links($iLink).href)
   Local $href = $oIE.document.links($iLink).href
   ;Click the link
   _IELinkClickByIndex($oIE,$iLink)
   ;If SomthingBadHappens Then SetError(1)
   ;get results, return pass/fail etc.....
EndFunc

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×