How to export a UDT from a Class

Tech-Archive recommends: Fix windows errors by optimizing your registry



I have a problem with exporting a UDT from a Public class and have it being
modifiable. It may be related to something I thought was a bug a couple of
years ago
(http://groups.google.ie/group/microsoft.public.vb.bugs/msg/4f99d5da34f04162
?hl=en)

Note that isn't the usual problem of not being able to export UDTs unless
the Type is Public and in a Public class. Everyone knows that one. No, in
this case, changes to the UDT just disappear. It's almost as though all
attempts to modify it are actually modifying a copy. This sounds likely
knowing that UDTs are assigned by value, not by reference. Obviously, trying
to export the UDT via a Property of the same UDT type will fail because a
copy would be exported. However, I get the same results when using a Variant
type too.

Here's a simplistic example of what is currently failing. Create a small
project group containing Form1 in a standard EXE, and Class1 in an ActiveX
DLL.

======= Form1 ==========
Dim o As Class1

Private Sub Command1_Click()
With o.Var
Debug.Print .s
End With
End Sub

Private Sub Form_Load()
Set o = New Class1
With o.Var
.s = "Hello"
Debug.Print .s
End With
End Sub
======================

======= Class1 ==========
Public Type t
s As String
End Type

Private tVar As t

Public Property Get Var() As Variant
Var = tVar
End Property
======================

The Form_Load sets the 's' member in the UDT, and a Debug.Print confirms it.
However, the Command1_Click shows it's no longer there. Hence, it seems
assigning a UDT to a Variant also seems to take a copy.

Anyone have any suggestions. I know someone will recommend switching from
UDTs to Objects but some of the members must be arrays, and you can't export
them directly from a Public class -- certainly not in a way that will allow
UBound and ReDim to work on them.

....arggg!

Tony Proctor


Tony Proctor


.



Relevant Pages

  • Re: How to export a UDT from a Class
    ... > the Type is Public and in a Public class. ... create a class property for each member of the UDT and it works always. ... Dim o As Class1 ... Private Sub Command1_Click ...
    (microsoft.public.vb.bugs)
  • Re: Probably a stupid UDT question, but...
    ... Björn, or something similar in a Form -- correct me if I'm wrong ... The problem is that your method almost certainly has a "Public" declaration. ... Public Class of an ActiveX component, or change the declaration of that ... > I tried to make a class with this UDT, as you said, but the problem (at ...
    (microsoft.public.vb.general.discussion)
  • a java newbie question
    ... What I need to do is to convert the following VB code to java. ... user-defined type (UDT) structure, copies that UDT to another UDT ... defined as String, then passes that string to the client component. ... public class Car_glo_604_reply_def { ...
    (comp.lang.java.programmer)
  • Re: Probably a stupid UDT question, but...
    ... I tried to make a class with this UDT, as you said, but the problem (at ... least I think so) is that to get a public class you have to write an ActiveX ... >> When I try to declare variables in form modules I get the error above. ...
    (microsoft.public.vb.general.discussion)
  • Re: Probably a stupid UDT question, but...
    ... Again, thanks for you response. ... I guess the solution is not to have it as a UDT at all but as ... > I'm assuming that you're passing one of your UDTs to a method in a Class ... > Public Class of an ActiveX component, or change the declaration of ...
    (microsoft.public.vb.general.discussion)