Jump to content

Bubble up (Return) multiple Functions?


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...