Sign in to follow this  
Followers 0

Check that function exists


21 posts in this topic

Posted

Hey guys,

I know that you can check to see whether a variable has been declared by using the function IsDeclared. Is there a similar function that can tell me whether a function exists?

Thanks.

Share this post


Link to post
Share on other sites



Posted

Unless I am missing what you're asking, SciTe should tell you if it detects a missing function when you try to Run/Compile. Otherwise, I would think you could check with CTRL + F5 (SyntaxCheck Prod).

Share this post


Link to post
Share on other sites

Posted

Alt + L also shows the UDF's on the active sheet...helpful to keep from scrolling up and down.

Share this post


Link to post
Share on other sites

Posted

IsDeclared should ideally be used when it's a last resort, though I've never used myself (did back a couple of years ago but that was bad!) Though I can't understand if you would like to know whether or not you've written a function, could you explain?

Share this post


Link to post
Share on other sites

Posted

$func = call("Function")
if @error then msgbox(1,"Failure","There is no such function")

Share this post


Link to post
Share on other sites

Posted (edited)

OfChange,

Looking at Call it states...

Both @error and @extended may contain values if the called function set them.

Edited by guinness

Share this post


Link to post
Share on other sites

Posted

OfChange,

Looking at Call it states...

Hmm I guess I missed that. I apologize for the misleading post then

Share this post


Link to post
Share on other sites

Posted

The reason I am asking is because I am writing a script at the moment in which I am using an array to store the menu information (It helps a lot with customization in the way of languages and customization of hotkeys). I am placing the names of the functions that need to be called in this array, and then when I use GuiCtrlSetOnEvent, if the function named by the array element doesn't exist, it doesn't error.

Share this post


Link to post
Share on other sites

Posted

The reason I am asking is because I am writing a script at the moment in which I am using an array to store the menu information (It helps a lot with customization in the way of languages and customization of hotkeys). I am placing the names of the functions that need to be called in this array, and then when I use GuiCtrlSetOnEvent, if the function named by the array element doesn't exist, it doesn't error.

Then make sure you use the right function names inside the array from the beginning. :)

Mikeman27294 likes this

Share this post


Link to post
Share on other sites

Posted (edited)

Do you sometimes read the help file :)

It clearly states:

"Sets @error to 0xDEAD and @extended to 0xBEEF if the function does not exist or invalid number of parameters."

$var = "Test1"
Call($var)
$Er = @error
$Ex = @extended
ConsoleWrite("$Er: " & $Er & " (dec), " & Hex($Er, 4) & " (hex); $Ex: " & $Ex & " (dec), " & Hex($Ex, 4) & " (hex)" & @CRLF)

Call("Test2")
$Er = @error
$Ex = @extended
ConsoleWrite("$Er: " & $Er & " (dec), " & Hex($Er, 4) & " (hex); $Ex: " & $Ex & " (dec), " & Hex($Ex, 4) & " (hex)" & @CRLF)

Func Test2($param1)

EndFunc   ;==>Test2

Gives you

$Er: 57005 (dec), DEAD (hex); $Ex: 48879 (dec), BEEF (hex)
$Er: 57005 (dec), DEAD (hex); $Ex: 48879 (dec), BEEF (hex)
with Autoit 3.3.8.0

@Extended doesn't seem to work (always returns 0) but @error does. It returns @error and @extended as described.

Edited by water

Share this post


Link to post
Share on other sites

Posted

"Sets @error to 0xDEAD and @extended to 0xBEEF if the function does not exist or invalid number of parameters."

Dead and beef, really..? :)

Share this post


Link to post
Share on other sites

Posted

Very old convention.

Share this post


Link to post
Share on other sites

Posted

Check this: Hexspeak

Share this post


Link to post
Share on other sites

Posted

Aaaah.

Makes sense now. :)

Share this post


Link to post
Share on other sites

Posted

Then make sure you use the right function names inside the array from the beginning. ;)

Yes, that would help, but I would like to have error alerts in my program if it doesn't work.

Do you sometimes read the help file :)

It clearly states:

"Sets @error to 0xDEAD and @extended to 0xBEEF if the function does not exist or invalid number of parameters."

I always read the help file. But I am not using the call function, I am using GuiCtrlSetOnEvent, as mentioned earlier.

Share this post


Link to post
Share on other sites

Posted

As far as I am aware of, there's no function that checks to see if a function exists. Even if there were, you'd still have to recurse through your array of function names and check them individually, which kind of defeats the purpose of checking it in the first place because you can do it manually just as easily.

Share this post


Link to post
Share on other sites

Posted

Then you'd have to write a function to check to ensure your function to check functions is functioning. I believe that is one of the signs of the Apocalypse :)

Share this post


Link to post
Share on other sites

Posted

Recursion level has been exceeded - The earth will cease to exist to prevent noob overflow.

Share this post


Link to post
Share on other sites

Posted

I think the best way for you to go about this is to handle the error if it occurs.

Are you dynamically setting hotkeys via user input, where they enter the name of a function?

If this is the case, then I suggest you test the result of hotkeyset, as that will fail if the function does

not exist.

Share this post


Link to post
Share on other sites

Posted

Ok, thanks guys. It's not a requirement, just something I was hoping to get running. Oh well, I will survive :)

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  
Followers 0