Jump to content
Sign in to follow this  
saywell

Newbie query

Recommended Posts

saywell

Hi,

I've got a GUI menu (though this isn't a GUI question) that runs several different functions according to which button is clicked.

It's all working OK but I now need to develop some error-trapping so something appropriate happens if things go wrong.

What I have so far failed to do is work out a way of ending a function prematurely if certain criteria are (or aren't) met.

I've tried various ifs and whiles, but if I put an 'endfunc' command anywhere within the function (even if it's in a branch of the conditional pathway) it's interpreted as the end of the function, and Scite tells me off for having an extra endfunc (ie the one in the conditional path, and the one at the proper end of the function.

Can anyone point out to me what I'm missing.

An example to clarify:

I want to run a function that does something only if a variable is less than 10. Otherwise the function should end as soon as the variable value has been checked (and return to main program).

Hope that's clear. I'm sure I've just missed something obvious to you guys!

Thanks,

William

Share this post


Link to post
Share on other sites
KaFu
azure

Hi,

I've got a GUI menu (though this isn't a GUI question) that runs several different functions according to which button is clicked.

It's all working OK but I now need to develop some error-trapping so something appropriate happens if things go wrong.

What I have so far failed to do is work out a way of ending a function prematurely if certain criteria are (or aren't) met.

I've tried various ifs and whiles, but if I put an 'endfunc' command anywhere within the function (even if it's in a branch of the conditional pathway) it's interpreted as the end of the function, and Scite tells me off for having an extra endfunc (ie the one in the conditional path, and the one at the proper end of the function.

Can anyone point out to me what I'm missing.

An example to clarify:

I want to run a function that does something only if a variable is less than 10. Otherwise the function should end as soon as the variable value has been checked (and return to main program).

Hope that's clear. I'm sure I've just missed something obvious to you guys!

Thanks,

William

Return a value?

Return(0) or Return(1) or whatever.

Or Just Return

Share this post


Link to post
Share on other sites
saywell

Return a value?

Return(0) or Return(1) or whatever.

Or Just Return

Just skip the rest of the function and return to the main prog to await another GUI button press.

EG I want to burn some files to a CD.

I check the directory size.

If it will fit on one CD it carries on with the rest of the function to burn the CD

If it won't fit on one CD it pops up a msgBox then I want it to skip the burning bits and abort the function, and retun control to the GUI.

William

Share this post


Link to post
Share on other sites
azure

Just skip the rest of the function and return to the main prog to await another GUI button press.

EG I want to burn some files to a CD.

I check the directory size.

If it will fit on one CD it carries on with the rest of the function to burn the CD

If it won't fit on one CD it pops up a msgBox then I want it to skip the burning bits and abort the function, and retun control to the GUI.

William

Yeah.. use

Return

to exit a function. You don't have to return a value.

Share this post


Link to post
Share on other sites
FireFox

Return isnt generaly used for return something not for exit a function ...

Examples :

HotKeySet("{F8}", "_F8HK")
Global $F8 = False

Msgbox(64, 'test', _Func("0"))
MsgBox(64, 'test', _Func("1"))
MsgBox(64, 'test', _Func("2"))

While 1
Sleep(250)
If _F8() Then ;if returned right then
MsgBox(64, 'test', 'function f8 called !')
EndIf
WEnd

Func _F8HK()
Global $F8 = True
EndFunc

Func _F8()
If $F8 = True Then
Global $F8 = False
Return 1 ;when return 1, the function called return right 
EndIf
Return 0 ;return 0 = wrong
EndFunc

Func _Func($nb)
If $nb = 1 then
Return 'right !'
ElseIf $nb = 0 then
Return 'Wrong !'
EndIf
Return 'you loose !'
EndFunc

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
saywell

Return isnt generaly used for return something not for exit a function ...

Examples :

HotKeySet("{F8}", "_F8HK")
Global $F8 = False

Msgbox(64, 'test', _Func("0"))
MsgBox(64, 'test', _Func("1"))
MsgBox(64, 'test', _Func("2"))

While 1
Sleep(250)
If _F8() Then ;if returned right then
MsgBox(64, 'test', 'function f8 called !')
EndIf
WEnd

Func _F8HK()
Global $F8 = True
EndFunc

Func _F8()
If $F8 = True Then
Global $F8 = False
Return 1 ;when return 1, the function called return right 
EndIf
Return 0 ;return 0 = wrong
EndFunc

Func _Func($nb)
If $nb = 1 then
Return 'right !'
ElseIf $nb = 0 then
Return 'Wrong !'
EndIf
Return 'you loose !'
EndFunc

Cheers, FireFox.

Thanks, Firefox. Sorry for the confusion between 'return' as in 'return a value' (tech-speak) and 'return' as in 'go back to' (everyday-english speak)!

So do I understand you correctly in that instead of doing the test within the function you do the test first, then call a different function depending on the result?

If so, I presume it's OK to call a function from within another function (sorry if this is a bleeding obvious newbie question!)? If not, I could run the 'while' bit where folder size is tested within the GUI while loop, perhaps?

William

Share this post


Link to post
Share on other sites
saywell

I think the answer is in a recent post.

Return seems to do what I want - I'll give it a try later.

William

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  

×