Solved

ActiceX and Not Remember Properties

Posted on 2004-08-26
3
184 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
ID: 11910217
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
ID: 11910709
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
ID: 11910735
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

Industry Leaders: 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!

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

685 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