Re: Questions about GetRef() and ASP, etc.
From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 03/02/04
- Next message: Mike Schinkel: "Re: Questions about GetRef() and ASP, etc."
- Previous message: Al Dunbar [MS-MVP]: "Re: Can I do client side populations from my ASP Page?"
- In reply to: Mike Schinkel: "Questions about GetRef() and ASP, etc."
- Next in thread: Mike Schinkel: "Re: Questions about GetRef() and ASP, etc."
- Reply: Mike Schinkel: "Re: Questions about GetRef() and ASP, etc."
- Reply: Joe Earnest: "Re: Questions about GetRef() and ASP, etc."
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 1 Mar 2004 21:42:31 -0700
"Mike Schinkel" <mikes@xtras.com> wrote in message
news:%23MedU5%23$DHA.2600@TK2MSFTNGP09.phx.gbl...
> I'm using ASP and VBScript and need the following functions (or their
> functionality):
>
> IsSub() '-- Tells me if a sub exists in global
> namespace
> IsFunction() '-- Tells me if a function exists in global
> namespace
> IsMethod() '-- Tells me if a sub or function exists for an
> object
> IsProperty() '-- Tells me if a property exists for an object
> ParameterCount() '-- Tells me how many parameters a sub or function
has
> defined
> Parameters() '-- Returns list of parameter names for given
sub
> or function
> IsFunction() '-- Tells me if a function exists in global
> namespace
> CallByName() '-- Lets me execute a sub or function by name with
> optional parameters
> CallStack() '-- Returns array objects where the objects
have
> Source File and Line Number of calling programs
> I thought I found some of this functionality with GetRef(), but found it
> to be one screwed up function!
Not really - it just failed to meet your (over)expectations.
Your "isWhatever" functions will not be able to accept the name of a
possible function. For example, consider:
MsgBox VarType( func )
MsgBox TypeName( func )
MsgBox VarType( Zfunc )
MsgBox TypeName( Zfunc )
Function func
func = 22
End function
The two msgbox dialogs display these four values: "2", "integer", "0", and
"empty", as the reference of the function resulted in it being called, and
the reference of the non-existent function could not be differentiated from
a non-existent variable of the same name
I think the only way you could achieve what you are looking for would be to
write your own code-parsing library and pass identifier names as literal
strings (isFunction( "func" )).
Others likely know tricks I am unaware of, however, I think you have set
yourself quite a task here.
/Al
> Assume the following ASP file (it is
> documented for what happens. After the file I'll explain in english):
>
> <%
>
>
'---------------------------------------------------------------------------
> ---------
> 'The following code outputs the following:
> 'In FooBar
> '0
> 'Object
> '9
> 'Object
> 'HowDy
> 'In FooBar#2
>
>
> Dim subref
>
> Set subref= GetRef( "FooBar" )
> Response.Write VarType(subref)& "<br>" '-- Executes FooBar writing "In
> FooBar", then writes "0"
> '-- vbEmpty is 0
> Response.Write TypeName(subref)& "<br>" '-- Writes "Object"
>
> Set subref= GetRef( "FooBar2" )
> Response.Write VarType(subref)& "<br>" '-- Writes "9" -- vbObject is
9
> Response.Write TypeName(subref)& "<br>" '-- Writes "Object"
> subref("Howdy") '-- Executes FooBar2, writes
> "Howdy" then "In FooBar#2"
>
>
> Sub FooBar()
> Response.Write "In FooBar<br>"
> End Sub
>
> Sub FooBar2(x)
> Response.Write x & "<br>"
> Response.Write "In FooBar#2<br>"
> End Sub
>
>
'---------------------------------------------------------------------------
> ---------
> %>
>
> Basically, if you assign subref= GetRef("NoParamSub") to where
NoParamSub
> is a Sub with no parameters, then accessing it by passing it to VarType()
> executes the sub, and the return value of the sub returns is interpretted
as
> zero, which is why VarType(subref) returns 0.
>
> If you assign subref= GetRef("HasParamsSub") to where HasParamsSub is a
> Sub with one or more parameters, then passing it is passed to VarType() as
> an object and VarType(subref) returns 9 (9 is the value of vbObject).
>
> Passing subref for both NoParamSub and HasParamsSub to TypeName()
returns
> "Object", which is what I'll have to use. I'd like to see VarType() fixed
> to return 9 for VarType(GetRef("NoParamSub")), but I won't hold my breath.
>
> Anyone know how to get some of the features I need while in ASP? Are
any
> in VBScript and I just don't know how?
>
> Also, what does the object returned by GetRef look like? Does it have
> properties or methods?
>
> TIA.
>
> -Mike
> P.S. If anyone can forward this to Eric Lippert, it would be greatly
> appreciated.
>
>
- Next message: Mike Schinkel: "Re: Questions about GetRef() and ASP, etc."
- Previous message: Al Dunbar [MS-MVP]: "Re: Can I do client side populations from my ASP Page?"
- In reply to: Mike Schinkel: "Questions about GetRef() and ASP, etc."
- Next in thread: Mike Schinkel: "Re: Questions about GetRef() and ASP, etc."
- Reply: Mike Schinkel: "Re: Questions about GetRef() and ASP, etc."
- Reply: Joe Earnest: "Re: Questions about GetRef() and ASP, etc."
- Messages sorted by: [ date ] [ thread ]