jmt-ga,
Before I start, if you have any questions regarding my answer, please
feel free to ask for clarifications before your rate me. I am willing
to work until you are completely satisfied.
To do this in ASP using VBScript:
<%
class x
'declares a public variable rs
dim rs
'Class_Initialize is the constructor function name for ASP VBScript
private sub Class_Initialize()
set rs = CreateObject("scripting.dictionary")
rs("stuff") = "xyz"
end sub
end class
'creates an x object, setting x.rs("stuff") to "xyz"
set obj = new x
'dot notation is used in vbscript to access variables
y = obj.rs("stuff")
response.write(y)
%>
For more information regarding ASP functions and classes, see:
http://www.sloppycode.net/asp-components/tutorial/?page=3
http://www.devguru.com/Technologies/vbscript/quickref/Class.html
Cheers,
Tox-ga |
Clarification of Answer by
tox-ga
on
14 Jun 2004 23:00 PDT
jmt-ga,
Sorry about that, please ignore the code above. I accidentally left
out a function. The following is the working code, with the default
function. Feel free to ask for clarifications if you don't understand
how it works.
<%
class x
'declares a public variable rs
dim rs
'Class_Initialize is the constructor for VBScript
private sub Class_Initialize()
'creates the rs dictionary object
set rs = CreateObject("scripting.dictionary")
'initializes the rs("stuff") variable
rs("stuff") = "xyz"
end sub
'the "default" keyword indicates that this function is default
'the "test" word is the function name
public default function test (inputstring)
'returning things in VBScript is done by equating the function
'name to whatever you wish to return
test = rs(inputstring)
end function
end class
set obj = new x
y = obj("stuff")
'prints "xyz"
response.write(y)
%>
Cheers,
Tox-ga
|
Request for Answer Clarification by
jmt-ga
on
14 Jun 2004 23:12 PDT
Sorry, but this isn't what I'm looking for.
I've been writing code for a decade now, and I've used vb and vbscript
quite a lot in the past several years. I've tried many times to find
the answer, so I don't expect it to be easy to find.
>> 'dot notation is used in vbscript to access variables
>> y = obj.rs("stuff")
I know this, but it is what I'm trying to avoid. In C++, an object
may be called as a function, this makes it a function object.
Optionally, a parameter may be passed in. In VB, an advanced option
may be set in a class object that causes the function to serve as the
default, but it doesn't seem to work in vbscript.
The underlying question may be phrased as, 'how do you set function
attributes in vbscript?'. In particular, I need to set the following
attribute in class x:
attribute x.VB_UserMemId = 0
The goal is to make x into a function object, so that I can call
x("stuff") and invoke the specified function to index into whatever
embedded or inherited list the object uses.
Thanks,
-Jmt
JackMThompson.com
|
Clarification of Answer by
tox-ga
on
14 Jun 2004 23:14 PDT
Sorry about that, I actually fixed the code if you look at my
clarification above. The way to do default functions is there.
Apologies again for the confusion.
Cheers,
tox-ga
|
Clarification of Answer by
tox-ga
on
14 Jun 2004 23:20 PDT
jmt-ga,
This is a copy of the clarification from above. If you have anymore
questions, feel free to ask.
<%
class x
'declares a public variable rs
dim rs
'Class_Initialize is the constructor for VBScript
private sub Class_Initialize()
'creates the rs dictionary object
set rs = CreateObject("scripting.dictionary")
'initializes the rs("stuff") variable
rs("stuff") = "xyz"
end sub
'the "default" keyword indicates that this function is default
'the "test" word is the function name
public default function test (inputstring)
'returning things in VBScript is done by equating the function
'name to whatever you wish to return
test = rs(inputstring)
end function
end class
set obj = new x
y = obj("stuff")
'prints "xyz"
response.write(y)
%>
Cheers,
Tox-ga
|
Clarification of Answer by
tox-ga
on
14 Jun 2004 23:48 PDT
jmt-ga,
If the line-by-line comments before seemed belittling or insulting, I
did not mean any offense. I merely wished to be clear. As you know,
VBScript and VB, while similar, have important differences
(http://www.hackerscenter.com/KnowledgeArea/guides/books/vbscript1/ch13fi.htm).
As a scripting language, VBScript has much less functionality when
compared to VB.
One of these key differences is the manner in which functions are
declared. The VBScript sytax for function declaration is
http://17.webmasters.com/caspdoc/html/vbscript_function_statement.htm.
However, even this extensive documentation leaves out that the way to
make a function default for the class is to have the "default" keyword
in the function header.
VB_UserMemId is actually a legal identifier in VBScript, while it is
not in VB, indicating that it serves no particular purpose in the
scripting form of the langauge.
(http://weblogs.asp.net/ericlippert/archive/2004/06/10/152831.aspx)
The default key word is the way to go.
I hope this clears things up for you.
Cheers,
tox-ga
|