Solved

ActiceX and Not Remember Properties

Posted on 2004-08-26
3
182 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy a row 12 63
Prevent user closing word document opened with VB6 6 78
Help with retrieving partial value from a column using VB.NET 4 51
Problem to line 23 53
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

809 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