
Call Let/Get Prop using string variable for name
George,
If you don't mind to write
clsX.Test = clsB.Properties(strName)
instead of
clsX.Test = clsB.Co_Type
then I think you can use the following class as template for your solution:
Private Const mcstrClassName As String = "CPrps"
Dim mcolPrps As New VBA.Collection
Public Property Get Properties( _
ByVal vstrPrpName As String) As Variant
If IsObject(mcolPrps(vstrPrpName)) Then
Set Properties = mcolPrps(vstrPrpName)
Else
Properties = mcolPrps(vstrPrpName)
End If
End Property
Public Property Let Properties( _
ByVal vstrPrpName As String, _
ByRef vvar As Variant)
On Error GoTo Properties_Err
mcolPrps.Remove vstrPrpName
Properties_Err:
On Error GoTo 0
mcolPrps.Add vvar, vstrPrpName
End Property
And this is a test:
Public Sub A_Test()
Dim prps As New CPrps
prps.Properties("IntNum") = 1
prps.Properties("String") = "two"
prps.Properties("CodeDB") = CodeDb()
prps.Properties("App") = Application
End Sub
HTH,
Shamil
Quote:
>I need to call a Let or Get property using a string variable rather than
the
>property's actual name because I'm using a generic class module as a
>go-between other class modules. for example,
>clsA needs to get a value from clsB, but for reasons, clsA and clsB will be
>communicating via a generic class module called clsX. clsA will pass a
>number of parameters and intructions of things to do into clsX and then
pass
>clsX into clsB. one of the string parameters will be the name of the Get
>property we want to retrieve a value from like: "Co_Type"
>This is how I'm trying to make it work.
>strName = "Co_Type"
>----------------------------------------
>'Get Prop in clsB
>Public Property Get Co_Type() as String
> Co_Type = udtProps.Co_Type
>End Property
>---------------------------------------
>clsX.Test = clsB(strName) 'instead of clsB.Co_Type
>Somehow I want to call the Property Co_Type by using strName
>Any ideas???
>Thanks.
>--
>George Padvorac