Jump to content

Newbie query


saywell
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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...