Call Let/Get Prop using string variable for name 
Author Message
 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




Mon, 27 Aug 2001 03:00:00 GMT  
 Call Let/Get Prop using string variable for name

says...
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,

Gonna be tough in this version of Access.  You might consider creating a
properties collection in your class, indexed by name (Access does this
for most of its properties -- and it's a wonderful feature). THen you can
refer to your properties within the Properties collection by name.

In Access 2000 (it's VBA 6.0 that provides this, actually), you can use
the CallByName function to call a method by name. You can convert a
property into a method, and use it that way, if you like. -- Ken



Mon, 27 Aug 2001 03:00:00 GMT  
 Call Let/Get Prop using string variable for name
Thanks Ken.

When you said

Quote:
>>(Access does this

for most of its properties -- and it's a wonderful feature).

are you talking about a built in collection feature of vba for custom
properties, or just a plain old collection object where each item is a text
string equal to the name of each custom Get property I created?

Quote:


>says...
>> 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,

>Gonna be tough in this version of Access.  You might consider creating a
>properties collection in your class, indexed by name (Access does this
>for most of its properties -- and it's a wonderful feature). THen you can
>refer to your properties within the Properties collection by name.

>In Access 2000 (it's VBA 6.0 that provides this, actually), you can use
>the CallByName function to call a method by name. You can convert a
>property into a method, and use it that way, if you like. -- Ken



Tue, 28 Aug 2001 03:00:00 GMT  
 Call Let/Get Prop using string variable for name

says...
Quote:
> When you said
> >>(Access does this
> for most of its properties -- and it's a wonderful feature).

> are you talking about a built in collection feature of vba for custom
> properties, or just a plain old collection object where each item is a text
> string equal to the name of each custom Get property I created?

Neither. And both. Access developers added a Properties collection to
most of the objects in Access. It's a difficult, painstaking task, but it
makes programming much easier. If you want to do what you're describing,
you'll need to add a property named Properties to your class, and have it
expose a collection containing one item for each property, with a key
value that is the name of the property. -- Ken


Tue, 28 Aug 2001 03:00:00 GMT  
 Call Let/Get Prop using string variable for name
<TANGENT>
In theory someone could write the VB6/VBA6 feature of CallByName that takes
an object and will properly use IDispatch::Invoke to call the right prop or
method.... but the work to do this yourself (create the typelib , implement
the code for it, and find yourself writing C++ code in VBA) is hardly worth
the benefit.

Note to the crazy lifeless people out there (like myself!)... I am not
claiming this is impossible; it is entirely possible to do. I just don't
think its worth it. :-)
</TANGENT>

Michael


Quote:

> says...
> > When you said
> > >>(Access does this
> > for most of its properties -- and it's a wonderful feature).

> > are you talking about a built in collection feature of vba for custom
> > properties, or just a plain old collection object where each item is a
text
> > string equal to the name of each custom Get property I created?

> Neither. And both. Access developers added a Properties collection to
> most of the objects in Access. It's a difficult, painstaking task, but it
> makes programming much easier. If you want to do what you're describing,
> you'll need to add a property named Properties to your class, and have it
> expose a collection containing one item for each property, with a key
> value that is the name of the property. -- Ken



Tue, 28 Aug 2001 03:00:00 GMT  
 Call Let/Get Prop using string variable for name
Sounds like it could be worth it if it were generic and could be re-used
once created.  Since I don't know C++ or have any C++ programmers at hand,
it seems a bit out of reach for now, But, it it was generic, it would be
worth my taking note for future use.

Could it be generic?

Quote:

><TANGENT>
>In theory someone could write the VB6/VBA6 feature of CallByName that takes
>an object and will properly use IDispatch::Invoke to call the right prop or
>method.... but the work to do this yourself (create the typelib , implement
>the code for it, and find yourself writing C++ code in VBA) is hardly worth
>the benefit.

>Note to the crazy lifeless people out there (like myself!)... I am not
>claiming this is impossible; it is entirely possible to do. I just don't
>think its worth it. :-)
></TANGENT>

>Michael




>> says...
>> > When you said
>> > >>(Access does this
>> > for most of its properties -- and it's a wonderful feature).

>> > are you talking about a built in collection feature of vba for custom
>> > properties, or just a plain old collection object where each item is a
>text
>> > string equal to the name of each custom Get property I created?

>> Neither. And both. Access developers added a Properties collection to
>> most of the objects in Access. It's a difficult, painstaking task, but it
>> makes programming much easier. If you want to do what you're describing,
>> you'll need to add a property named Properties to your class, and have it
>> expose a collection containing one item for each property, with a key
>> value that is the name of the property. -- Ken



Fri, 31 Aug 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Call Let/Get Prop using string variable for name

2. Call a proc using a string variable for the proc name

3. Naming convention for seriescollection(arg).name using a string variable

4. Calling function or sub with variable array or string names

5. how do i call a function by using the function name as a string of characters

6. calling a contol on a form using a string for the form name

7. Help with using names and variables in a function call

8. Calling a procedure using a variable name

9. Call Function using Func Name stored in variable

10. Calling a sub procedure whose name is in a variable: call me.ProcToRun


 
Powered by phpBB® Forum Software © phpBB Group