|
|
|||||||
Ran into an interesting situation today...Should this return true? What is it returning? @Error still says 0. Code: If NonExistentFunction() ? "yes" else ? "no" endif get $ |
||||||||
|
|
|||||||
0 = true - it's non existing ;). I've never seen an if statement checking if a function exists before tho.. |
||||||||
|
|
|||||||
Ha I know right. Me either... But been messing around with kix2exe, and trying to get it's built-in kixforms registration UDF to work. http://kix2exe.ramonitor.nl/udfs.php#k2e_registerkixforms From the site... Code: If $K2E_KixformsEnabled = True If K2E_RegisterKixforms() = True $System = CreateObject("Kixtart.System") EndIf Else ; code if K2E_RegisterKixforms() failed EndIf That first line isn't always returning true like it should, so I tried removing it and just checking for UDF. But...That second line always returns true lol. |
||||||||
|
|
|||||||
It's correct, if a little confusing when you know that:
So because the function does not exist in the KiXtart syntax dictionary it is assumed to be a simple string and as it is not null it's boolean value is true. In your example even the word True is not a boolean, it is a non-zero string. If you replaced your True with False it would work exactly the same, which could be a bit confusing. KiXtart does catch bare strings in some cases, which can also be a little confusing to neophytes, In the following example the first three work but the last does not: Code: ""+Hello+@CRLF CStr(Hello) @CRLF "" "Hello" @CRLF "" Hello @CRLF |
||||||||
|
|
|||||||
As parenthesis are optional for functions, here is a simple way to test for function existance: Code: If CStr(Foo) = "Foo" "Foo does not exist!"+@CRLF Else "Foo exists"+@CRLF EndIf If CStr(Bar) = "Bar" "Bar does not exist!"+@CRLF Else "Bar exists"+@CRLF EndIf Function Foo() exit 0 EndFunction This correctly reports: Quote: Foo exists Bar does not exist! |
||||||||
|
|
|||||||
Nice. Thanks for the info Richard, much appreciated. |
||||||||
|
|
|||||||
You're welcome. If the function has mandatory parameters you'll need to adjust the check accordingly of course. |