PartyPooper Posted December 3, 2005 Posted December 3, 2005 Here is my dilemma: How do I exit a FileOpenError() back to the main code without running all the lines of code left in Two() after an error? ;.... Two() ;.... Func Two() ;.... $OpenFile = FileOpen(@ScriptDir & '\' & $File, 0) If $OpenFile = -1 Then FileOpenError() ;.... ;.... EndFunc Func FileOpenError() MsgBox(262160, "ERROR", "Unable to open file.") ;Return - will only take me back to Two() which I don't want ;Exit - will dump me out of the script which I don't want EndFunc
PartyPooper Posted December 3, 2005 Author Posted December 3, 2005 (edited) Should of mentioned I originally had the following which worked but I wanted to clean up the code: Func Two() ;.... $OpenFile = FileOpen(@ScriptDir & '\' & $File, 0) If $OpenFile = -1 Then MsgBox(262160, "ERROR", "Unable to open file.") Return EndIf ;.... ;.... EndFunc Edit: those code tags again Edited December 3, 2005 by PartyPooper
Valuater Posted December 3, 2005 Posted December 3, 2005 (edited) Simple ;.... Two() ;.... Func Two() ;.... $OpenFile = FileOpen(@ScriptDir & '\' & $File, 0) If $OpenFile = -1 Then FileOpenError() Return *************** here ********************** ;.... ;.... EndFunc Func FileOpenError() MsgBox(262160, "ERROR", "Unable to open file.") ;Return - will only take me back to Two() which I don't want ;Exit - will dump me out of the script which I don't want Return '*******************here ********* EndFunc 8) Edited December 3, 2005 by Valuater
SumTingWong Posted December 4, 2005 Posted December 4, 2005 (edited) Or ;.... Two() ;.... Func Two() ;.... $OpenFile = FileOpen(@ScriptDir & '\' & $File, 0) If $OpenFile = -1 Then Return FileOpenError() ;.... ;.... EndFunc Func FileOpenError() MsgBox(262160, "ERROR", "Unable to open file.") Return $YourReturnCode ;Exit - will dump me out of the script which I don't want EndFunc Edited December 4, 2005 by SumTingWong
PartyPooper Posted December 4, 2005 Author Posted December 4, 2005 (edited) Sorry Valuater, I should have articulated a little better and expanded my example. I meant: Func Two() ;some code in here $OpenFile = FileOpen(@ScriptDir & '\' & $File, 0) If $OpenFile = -1 Then FileOpenError() ;some more code here ;even more code EndFunc Using your method would simply return me to the main code whether or not an error occured. Thanks for the response though. Thanks SumTingWong, I believe I can build on your example. I had a feeling it may have had something to do with returned function values (something I'm yet to understand and master). Edit: typo's Edited December 4, 2005 by PartyPooper
w0uter Posted December 4, 2005 Posted December 4, 2005 your code doesnt need cleaning up IMO. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
PartyPooper Posted December 4, 2005 Author Posted December 4, 2005 :-) If I was only going to use it once in a function, then I'd agree w0uter but unfortunately I'm opening several files within the same function and several more in other functions so I wanted a way of not repeating myself over and over and have errors creep in, as well as, being able to reduce the size of the script a little.
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