User defined type and variant ? 
Author Message
 User defined type and variant ?

Hi all,

I'm new in VB and the following code doesn't work...

Private Type my_type1
  arg1 As String
  arg2 As String
End Type

Private Type my_type2
  arg3 As String
  arg4 As Variant
End Type

Private Sub my_sub()
   Dim b As my_type2
   Dim tab(1) As my_type1

   tab(1).arg1 = "hello1"
   tab(1).arg2 = "hello2"
   b.arg3 = "hello3"
   b.arg3 = tab         ************* !!! Error detected here !!! *************
End Sub

The error is something like:

"Only public user defined types defined in public object
modules can be used as parameters [...] for public
procedures of class modules or as fields of user defined
types"

I really don't understand the problem, please help...

Bastien



Fri, 24 Dec 2004 16:27:54 GMT  
 User defined type and variant ?

Quote:
>   b.arg3 = "hello3"
>   b.arg3 = tab         ************* !!! Error detected here !!! *************
>End Sub

>The error is something like:

>"Only public user defined types defined in public object
>modules can be used as parameters [...] for public
>procedures of class modules or as fields of user defined
>types"

>I really don't understand the problem, please help...

That's one of those slightly misleading errors you get when VB can't
resolve a variable..  
There is no such thing as Tab, but if you use vbTab it should be fine.

Regards, Frank



Fri, 24 Dec 2004 16:38:24 GMT  
 User defined type and variant ?
Hi~!!

Shouldn't "b.arg3 = tab" be "b.arg4 = tab"? Because now you're assigning a
user-type array to a *string* (arg3 As String). It should work with b.arg4
(cuz. arg4 As Variant ofcourse).

Greetz,
Gerego



Quote:
> Hi all,

> I'm new in VB and the following code doesn't work...

> Private Type my_type1
>   arg1 As String
>   arg2 As String
> End Type

> Private Type my_type2
>   arg3 As String
>   arg4 As Variant
> End Type

> Private Sub my_sub()
>    Dim b As my_type2
>    Dim tab(1) As my_type1

>    tab(1).arg1 = "hello1"
>    tab(1).arg2 = "hello2"
>    b.arg3 = "hello3"
>    b.arg3 = tab         ************* !!! Error detected here !!!
*************
> End Sub

> The error is something like:

> "Only public user defined types defined in public object
> modules can be used as parameters [...] for public
> procedures of class modules or as fields of user defined
> types"

> I really don't understand the problem, please help...

> Bastien



Fri, 24 Dec 2004 17:13:31 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Convert user defined type or variant to byte array (and back)

2. User-Defined Types and Variants: VB6

3. how to convert user-defined TYPE to variant?

4. Q: variant data type with user defined data type

5. VARIANT array to user defined type mapping

6. Auto conversion from user defined type to variant possible?

7. User Control - User-defined type not defined

8. User Defined Type Not Defined

9. Compile Error: User-defined type not defined

10. User-defined type not defined (Access 97)

11. Excel : User-defined type not define

12. Compile Error - User defined type not defined

 

 
Powered by phpBB® Forum Software