Solved

ActiceX and Not Remember Properties

Posted on 2004-08-26
3
178 Views
Last Modified: 2013-11-26
Hi,

I have created and activex object that has a property for the path of a file. My problem is that when i put a path in the corresonse property spot then do something else in the project. when i come back the value is not there.

Am i going crazy or is this a problem?

Please help
0
Comment
Question by:cossy74
  • 2
3 Comments
 
LVL 5

Expert Comment

by:KarcOrigin
Comment Utility
Hi,

Have you played with UserControl_ReadProperties event and UserControl_WriteProperties event of the user control (Your activeX).

Cheers!
0
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
Try this method:

'------------------------------------------------------
Dim myPath As String                          'internal variable with which the control works with

Public Property Get Path() As String
    Path = myPath                                'when someone from outside wants to get the value of Path property, pass it the value from internal variable
End Property

Public Property Let Path(ByVal vNewValue As String)
    myPath = vNewValue                                                 'when something from the outside changes the property, forward the value to internal variable and...
    PropertyChanged "Path"                                             'report to visual basic that property was changed, so it can update the value in property list
End Property

Private Sub UserControl_InitProperties()
    myPath = "c:\"                                               'when control is first created, assign the default value to the property
    PropertyChanged "Path"
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "Path", myPath, "c:\"                                'when control is destroyed, (for example, you close the form), save the property value in the PropertyBag
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    myPath = PropBag.ReadProperty("Path", "c:\")                            'when the control is recreated (the form is oppened again), read the value from the PropertyBag
    PropertyChanged "Path"
End Sub
'--------------------------------------------------------------------------------

0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 500 total points
Comment Utility
Read this:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconcreatingactivexcontrol.asp

and especially "Life and Times of a UserControl Object"     ->     http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconlifetimesofusercontrol.asp

It will explain why you have to save properties and read them so often.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now