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.
From: Shamil Salakhetdinov <shamil@marta.darts.spb.ru>
Subject: Re: Call Let/Get Prop using string variable for name
Date: 12 March 1999 0:43
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
| HOME TOPICS |
Copyright © 1999 by Shamil Salakhetdinov.
|
| Last updated: October 10, 2006
Published also here at 4TOPS: Call Let/Get Prop using string variable for name |
|