I tried something like this.. just enough to show structure here
-------------------------------------
Class MyClass
Function DoSomething(oDataForMyClass)
'assume cmd is an ADODB.Command object
cmd.Parameters.Append oDataForMyClass.TestParameter 'I get a type
mismatch error here in the real code?
End Function
End Class
Class DataForMyClass
private pTestParameter
Private Sub Class_Initialize
Set pTestParameter = CreateObject("ADODB.Parameter")
pTestParameter.Type = adInt
End Sub
Property Let TestParameter(value)
pTestParameter.Value = value
End Property
Property Get TestParameter
TestParameter = pTestParameter 'shouldn't this return an
ADODB.Parameter object?
End Property
End Class
------------------------------------------
I get a type mismatch when I go to use what I thought should be an
ADODB.Parameter object. A propery 'get' is like a function right, it returns
something... can't it return an object? I need enlightenment on this
desperately!
And make sure somewhere you define adInt.
Tim
"James" <no...@nowhere.com> wrote in message
news:u90P1hzL...@TK2MSFTNGP05.phx.gbl...
I have a side question for you that is somewhat related:
When an object is passed into a function or sub is it always passed byref?
In other words are objects (even your own classes) exceptions to the use of
byref or byval functionality in that they can only be passed byref and
therefore are?
"Tim Williams" <timjwilliams at gmail dot com> wrote in message
news:ervCw6zL...@TK2MSFTNGP02.phx.gbl...
Object variables hold a reference to the (data of the) object. So
passing an object per value still gives the called sub/function access
to the object('s data) - you can't prevent the callee from doing nasty
things to your object. But if you pass this reference per reference,
the called sub/function may even change the caller's variable('s content):
Class cPerson
Private m_sName
Private m_nAge
Private Sub Class_Initialize()
WScript.Echo "*", "Creating a cPerson object"
End Sub
Public Function init( sName, nAge )
m_sName = sName
m_nAge = nAge
Set init = Me
End Function
Public Default Property Get data()
data = m_sName & " (" & m_nAge & ")"
End Property
Public Sub birthday()
m_nAge = m_nAge + 1
End Sub
End Class ' cPerson
Sub birthday( ByVal oP0, ByVal oP1 )
oP0.birthday
oP1.birthday
End Sub
Sub swapPerVal( ByVal oP0, ByVal oP1 )
Dim oTmp
Set oTmp = oP0
Set oP0 = oP1
Set oP1 = oTmp
oP0.birthday
End Sub
Sub swapPerRef( oP0, oP1 )
Dim oTmp
Set oTmp = oP0
Set oP0 = oP1
Set oP1 = oTmp
oP0.birthday
End Sub
Dim oAdam : Set oAdam = New cPerson.init( "Adam", 20 )
Dim oEve : Set oEve = New cPerson.init( "Eve" , 20 )
WScript.Echo 0, oAdam, oEve
birthday oAdam, oEve
WScript.Echo 1, oAdam, oEve
swapPerVal oAdam, oEve
WScript.Echo 2, oAdam, oEve
swapPerRef oAdam, oEve
WScript.Echo 3, oAdam, oEve
output:
=== ObjRefVal: objects - reference/value ==
* Creating a cPerson object
* Creating a cPerson object
0 Adam (20) Eve (20)
1 Adam (21) Eve (21)
2 Adam (21) Eve (22)
3 Eve (23) Adam (21)
=== ObjRefVal: 0 done (00:00:00) ==========
"Sub swapPerVal( ByVal oP0, ByVal oP1 )" will change Eve via the
(in effect local) variable oP0, but to really swap oAdam and oEve you
need "Sub swapPerRef( oP0, oP1 )".
"ekkehard.horner" <ekkehar...@arcor.de> wrote in message
news:48f78ca9$0$28913$9b4e...@newsspool1.arcor-online.net...