Solved

ActiceX and Not Remember Properties

Posted on 2004-08-26
3
188 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
[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
  • 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

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month7 days, 7 hours left to enroll

621 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