Refer to a member of User Defined Type by using a Variable's Value 
Author Message
 Refer to a member of User Defined Type by using a Variable's Value

Hi there,

Is it possible to refer to a member of a User Defined Type by using a
Variable's Value?

Example:

Private Type MyType
    CompanyName as Variant
    ProjectID as Variant
    ProjectName as Variant
End Type
Private MT as MyType

Private Function Test()
    Dim cName as String, i as Byte
    For i = 1 to 3
        cName  = Choose(i, "CompanyName", "ProjectID", "ProjectName")
    Next i
    MT(cName) = cName?
    MT.[cName] = cName?
    MT!cName = cName?
End Function

Is this possible?

Thank you,
Daniel Kaseman



Tue, 01 Mar 2005 23:51:44 GMT  
 Refer to a member of User Defined Type by using a Variable's Value
Hi Daniel,

Not that I know of, and I wouldn't dream of wanting to. Use an
array, a collection or a dictionary depending on just what you
need. Since your type consists of nothing but variants, you
might as well use something like

        Const iCompanyName as Integer = 0
        Const iProjectID as Integer = 1
        Const iProjectName As Integer = 2
        Dim MT as Variant(2)

        MT(iCompanyName) = "Company Name"
        MT(iProjectID) = "99"
        ...

On Fri, 13 Sep 2002 10:51:44 -0500, "Daniel Kaseman"

Quote:

>Hi there,

>Is it possible to refer to a member of a User Defined Type by using a
>Variable's Value?

>Example:

>Private Type MyType
>    CompanyName as Variant
>    ProjectID as Variant
>    ProjectName as Variant
>End Type
>Private MT as MyType

>Private Function Test()
>    Dim cName as String, i as Byte
>    For i = 1 to 3
>        cName  = Choose(i, "CompanyName", "ProjectID", "ProjectName")
>    Next i
>    MT(cName) = cName?
>    MT.[cName] = cName?
>    MT!cName = cName?
>End Function

>Is this possible?

>Thank you,
>Daniel Kaseman

John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.



Wed, 02 Mar 2005 04:20:34 GMT  
 Refer to a member of User Defined Type by using a Variable's Value
Thank you, John.  I will give it a try.

Daniel Kaseman

Quote:
> Hi Daniel,

> Not that I know of, and I wouldn't dream of wanting to. Use an
> array, a collection or a dictionary depending on just what you
> need. Since your type consists of nothing but variants, you
> might as well use something like

> Const iCompanyName as Integer = 0
> Const iProjectID as Integer = 1
> Const iProjectName As Integer = 2
> Dim MT as Variant(2)

> MT(iCompanyName) = "Company Name"
> MT(iProjectID) = "99"
> ...

> On Fri, 13 Sep 2002 10:51:44 -0500, "Daniel Kaseman"

> >Hi there,

> >Is it possible to refer to a member of a User Defined Type by using a
> >Variable's Value?

> >Example:

> >Private Type MyType
> >    CompanyName as Variant
> >    ProjectID as Variant
> >    ProjectName as Variant
> >End Type
> >Private MT as MyType

> >Private Function Test()
> >    Dim cName as String, i as Byte
> >    For i = 1 to 3
> >        cName  = Choose(i, "CompanyName", "ProjectID", "ProjectName")
> >    Next i
> >    MT(cName) = cName?
> >    MT.[cName] = cName?
> >    MT!cName = cName?
> >End Function

> >Is this possible?

> >Thank you,
> >Daniel Kaseman

> John Nurick [Microsoft Access MVP]

> Please respond in the newgroup and not by email.



Wed, 02 Mar 2005 04:58:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problems defining a user defined type variable for use on more than one form

2. Passing Strings as members of User Defined Types to an API call

3. User Control - User-defined type not defined

4. User defined types as Sub variables

5. Global Variables or User defined data type

6. Help with passing user defined types as variables in functions - VB4 32bit

7. Clearing user defined type variable

8. User-defined variable types

9. Can a user defined type have a variable number of items

10. User-defined error when the user doesn't define any errors

11. Check if User Defined Type has a values VB 6.0

12. Passing structures/user defined types to DLL's

 

 
Powered by phpBB® Forum Software