?
Solved

Passing variables in ActiveX DLL with form

Posted on 2003-03-10
8
Medium Priority
?
158 Views
Last Modified: 2013-11-26
I would like to know if there is a cleaner of way of doing this...

I have an ActiveX (DLL) project that contains a Public Class, a Form and a module. When the class is instantiated, one of the methods of the class is to show the Form, which acts basically as a visual interface to set the properties of the class. Now it's not that hard to access the properties of the class from the Form, but the only way I can see to set the properties in the class from the Form is to use public duplicate variables in a module, which is then accessable from the class. To me, this kind of defeats the object of data encapsulation? Surely there must be a better way to tranfer the values from the Forms' controls back to the Class' properties?

Thanx aloud!
0
Comment
Question by:CD-Softy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8105218
You could expose the object as in

Public Object as MyClass

and access it as follows

frm.Object.Property
0
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8105242
Forget that just re-read the question.

I use the same approach as you are stating.

e.g.

Public Property Get MyProp() as String
   MyProp = MyObject.MyProp
end Property
0
 
LVL 5

Accepted Solution

by:
bob_online earned 1000 total points
ID: 8105586
If you declare an object variable, with events of the form within the class like

Private WithEvents MyForm as frmWhatever

then you can do the following:

1)  In the validate event or lost focus event of each control on the form, raise an event which will be received by the class with the new value which can then set its own property.

2)  Set up properties on the form exposing the values to the class, i.e, Friend Property Get SomeValue() as String.
When the Ok button (or whatever) is clicked on the form, raise an event you have created such as FormClosed.  In the class, when the FormClosed event is received, retrieve the values from the form using the Friend properties.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:CD-Softy
ID: 8106012
bob online...

Clever! However, I can't seem to get it to work! I have done this...

<Class>

Private WithEvents frm as Form

Public Function ShowProperties()
     Set frm = frmProperties   'this is the form with visual interface.
     frm.Show vbModal          'this works fine!

End Function

>/Class>

<Form>

Public Event Test(Str as String)

Private Sub cmdOK_Click()
   RaiseEvent Test("Test")
   Unload Me
End Sub

</Form>

Now for some reason, the Class is not receiving the 'Test' event? I can't access the event proceedure from the drop-down list. I have even tried forcing an event...

Private Sub frm_Test(Str as String)
Msgbox str
End Sub

No joy, any ideas?


0
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8106092
Try changing

RaiseEvent Test("Test")
  Unload Me


for

RaiseEvent Test("Test")
DoEvents
Unload Me

Hope that is more help than the last comment.
0
 
LVL 3

Expert Comment

by:phildaley
ID: 8106318
Your declaration:
Private WithEvents frm as Form

Should be:
Private WithEvents frm as frmProperties

Now you should be able to select frm from left hand combo on code screen, and event Test from right hand combo
0
 
LVL 2

Author Comment

by:CD-Softy
ID: 8106423
Thank you to bob online and phildaley, with your combined answers it is now working perfectly. I want to split the award points between you - question is how.

Watch this space.... I'm off to find the answer.

Thankyou!
0
 
LVL 2

Author Comment

by:CD-Softy
ID: 8106528
EE - please help with my previous comment.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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 Month9 days, 9 hours left to enroll

762 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