Page 1 of 1 1
Topic Options
#202988 - 2011-08-26 06:31 PM Non-Existing Function returns
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
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 $

Top
#202989 - 2011-08-26 06:55 PM Re: Non-Existing Function returns [Re: ShaneEP]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
0 = true - it's non existing ;).
I've never seen an if statement checking if a function exists before tho..
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#202990 - 2011-08-26 07:14 PM Re: Non-Existing Function returns [Re: Björn]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
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.

Top
#203037 - 2011-09-06 11:56 AM Re: Non-Existing Function returns [Re: ShaneEP]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It's correct, if a little confusing when you know that:

  • In KiXtart speech marks around strings are optional. Any string (in the role of a parameter) which is not recognised as KiXtart syntax is assumed to be a string.
  • In KiXtart a non-zero length string is always true (even is it is "0")


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

Top
#203038 - 2011-09-06 12:06 PM Re: Non-Existing Function returns [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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!

Top
#203041 - 2011-09-06 04:28 PM Re: Non-Existing Function returns [Re: Richard H.]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2099
Loc: Tulsa, OK
Nice. Thanks for the info Richard, much appreciated.
Top
#203046 - 2011-09-07 10:34 AM Re: Non-Existing Function returns [Re: ShaneEP]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You're welcome.

If the function has mandatory parameters you'll need to adjust the check accordingly of course.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
2 registered (NTDOC, Allen) and 289 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

Generated in 0.045 seconds in which 0.013 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org