Re: function/sub isDefined? by Christoph
Christoph
Tue Sep 14 15:22:55 CDT 2004
14.09.2004 19:59, rob schrieb:
> Hey,
>
> I've looked every place I can think of ... is there a way to test to see
> if a Sub or a Function has been defined? I'm working in ASP classic 3.0.
>
> I need to do an IF statement and do something if something has been
> defined otherwise ... not ...
You can try to use it as a L-Value (assign sth to it). If you get err 501
then it's a sub, function, const, class or internal vbs-function
If you then try to GetRef it and get err 0 then its a defined sub or
function (not a const, class or internal)
This way you *don't* *execute* the putative Sub/Function
Which is the case if u use Call or Typename.
Option Explicit
Dim b, Name
Dim dummy : dummy = 0
Const c = "c"
Class k : end class
Sub s : End Sub
Function f : f = 0 : End Function
For each Name in Array ("dummy", "err", "true", "null", "c", "k", _
"s", "f", "if", "isDefinedProc", "class", "WScript", "Now", "me")
b = isDefinedProc (Name)
If b Then
MsgBox "'" & Name & "' IS a defined sub or function"
Else
MsgBox "'" & Name & "' is NOT a defined sub or function"
End If
Next
Function isDefinedProc (byval procName)
On error resume next
ExecuteGlobal "Option Explicit:" & procName & " = 1"
If err.number = 501 Then
err.clear : Dim foo
Set foo = GetRef(procName)
If err.number = 0 Then
isDefinedProc = true
Exit Function
End If
End If
isDefinedProc = false
End Function
--
Gruesse, Christoph
Rio Riay Riayo - Gordon Sumner, 1979