[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Read/Write to activeX dll's UDT

Posted on 2001-07-04
8
Medium Priority
?
309 Views
Last Modified: 2008-03-06
I have a UDT declared in my dll project's class:-

Public Type TFields
    ArrangingMortgageOrDiscussER As EArrMortDiscER
    ERPRPOverviewVisited As Boolean
    DiscussLTH As EBroadDetailCombo
    DiscussER As EYesNoCombo
    DiscussIHT As EYesNoCombo
'etc
End Type

and I am instancing the dll from my form in the exe project. During the initialisation, the TFields gets its data from the database and is made available to the form using:

Public Property Get ERFields() As TFields
    ERFields = mERFields
End Property

Public Property Let ERFields(NewFields As TFields)
    mERFields = NewFields
End Property

The problem is that I can't use:

Public Property Let ERFields(byVal NewFields As TFields)
 as this creates an error, and hence I can read the data using e.g.

Command1.Visible = obj.ERFields.ERPRPOverviewVisited

but I cant write the data back to the class using:

obj.ERFields.ERPRPOverviewVisited = True

... the value is lost. I do not want to have separate lets and gets for every single property. How else can I make a UDT in an activeX dll class read/write???? Any ideas????
0
Comment
Question by:PeteD
8 Comments
 
LVL 7

Expert Comment

by:John844
ID: 6253540
do you ever define the module variable mERFields?
like
Public Type TFields
   ArrangingMortgageOrDiscussER As EArrMortDiscER
   ERPRPOverviewVisited As Boolean
   DiscussLTH As EBroadDetailCombo
   DiscussER As EYesNoCombo
   DiscussIHT As EYesNoCombo
'etc
End Type

private mERFields as TFields
0
 
LVL 15

Expert Comment

by:ameba
ID: 6254018
> obj.ERFields.ERPRPOverviewVisited = True

Use this syntax:
     With obj.ERFields
         .ERPRPOverviewVisited = True
     End With
0
 
LVL 15

Expert Comment

by:ameba
ID: 6254025
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:Aaron_Young
ID: 6254039
In your example you're passing the structure to the property by value, you should be passing it by reference, i.e.

    Public Property Let ERFields(ByRef NewFields As TFields)

Regards,

- Aaron.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6254058
Hehe, welcome Aaron
Good to see you here!
ameba (Bruno on Codeguru)

Yes, it should be ByRef, I forgot to mention that part of the problem.
0
 
LVL 2

Author Comment

by:PeteD
ID: 6254787
ameba,

from your previous EE accepted answer:

caraf_g,

Yes, 'Friend' works only in the same project.

If UDT must be Public, so it can be passed between components, then it must be defined in public class
module.

Project should be ActiveX EXE (or any other ActiveX project type)
Change project to ActiveX EXE.
Set it's Startup mode to Standalone (project properties, components tab)

' Class2, set Instancing=6 'GlobalMultiUse -----
Option Explicit
Public Type a
  X As Integer
  Y As Integer
End Type

' module1 -------------
Option Explicit

Sub main()
   Form1.Show
End Sub

' Class1 ------------
Option Explicit
Private m_a1 As a

Public Function a1() As a
   a1 = m_a1
End Function

' form1 ------------
Option Explicit
Dim MyFrm As Class1

Private Sub Form_Click()
   Set MyFrm = New Class1
   With MyFrm.a1
       .X = 10
       MsgBox .X     'WORKS, but
   End With
   Msgbox MyFrm.a1.x  'DOESN'T work
End Sub


i.e. it can only be set, and then read within the same with > end with clause ????????
0
 
LVL 15

Accepted Solution

by:
ameba earned 400 total points
ID: 6255023
>i.e. it can only be set, and then read within the same with > end with clause ????????

Yes,  "With MyFrm.a1"  must be used - it will create temporary object.  That internal object has some address and that allows passing address (passing by reference).
The other, "normal" syntax will really pass value (expression).

Well, maybe term "internal object" is not good, since UDTs are not objects.

Anyway, to pass ByRef, the declaration is not enough - you must pass a variable, you cannot pass an "expression", see this PAQ (1 pts)
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20137162
0
 
LVL 2

Author Comment

by:PeteD
ID: 6326906
Thanks all for your input! I got round this by declaring my UDT locally, and then passing it back to the class before saving to the database. It's a shame that you have to do this in VB :-( but there we go!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question