WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinBatch Function UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Detecting if a Function Exists


Question:

Is there any way to detect if a function exists?

Answer:

If VarType returns -1 then it is some kind of reserved word. See if it is in WIL.CLR That would pick up functions even in unloaded extenders. Indeed, namespace pollution is an issue.

User Reply:

This UDF I whipped up seems to fit the bill:
;******************************************************************************
; This makes sure that some uncommon special chars are recognized by most browsers.
;
; Returns:
;     @FALSE    The function has not been defined.
;          1    The function is intrinsic to WIL.
;          2    The function is defined by the calling application (i.e. AutoIntern, etc.)
;          3    The function is defined in an extender.
;          4    The function is a UDF.
;******************************************************************************
#DefineFunction FunctionDefined (p_sName)
   sFF = Num2Char(255)
   sFuncs100 = IntControl (77, 100, 0, 0, 0) ; Intrinsic to WIL
   For n=1 To ItemCount (sFuncs100, @TAB)
      sFuncEntry = ItemExtract (n, sFuncs100, @TAB)
      If (StriCmp(ItemExtract(6,sFuncEntry,sFF), p_sName) == 0)
         Return 1
      EndIf
   Next n

   sFuncs101 = IntControl (77, 101, 0, 0, 0) ; Calling app
   For n=1 To ItemCount (sFuncs101, @TAB)
      sFuncEntry = ItemExtract (n, sFuncs101, @TAB)
      If (StriCmp(ItemExtract(6,sFuncEntry,sFF), p_sName) == 0)
         Return 2
      EndIf
   Next n

   sFuncs102 = IntControl (77, 102, 0, 0, 0) ; Extenders
   If (ItemLocate(StrLower(p_sName),sFuncs102,@TAB) > 0)
      Return 3
   EndIf

   sFuncs103 = IntControl (77, 103, 0, 0, 0) ; UDFs
   If (ItemLocate(StrLower(p_sName),sFuncs103,@TAB) > 0)
      Return 4
   EndIf

   Return @FALSE
#EndFunction

If (FunctionDefined ("Message"))
   Message ("", "Message exists")
Else
   Message ("", "Message DOES NOT exist")
EndIf

If (FunctionDefined ("ALogMessage"))
   Message ("", "ALogMessage exists")
Else
   Message ("", "ALogMessage DOES NOT exist")
EndIf

Exit

Article ID:   W17278
File Created: 2007:07:03:14:29:14
Last Updated: 2007:07:03:14:29:14