Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX component. 1

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
GB
Hi everyone,

All i'm wanting to do is have a property on my activeX control which i can change. Then the value is used in the activex control! simple?

i'm sorta using the Public Property Get sub but it can't get the value :(

Any sample code on doin this?

Cheers
:-s:-s:-s:-s
 
A Property Get procedure will return a value from the control to the calling procedure. If you want to change the value, use a Property Let (or Set for objects)

an example would be:
'm_MyInteger is private to the control

Property Let MyInteger(ByVal NewValue as Integer)
If IsNumeric(NewValue) = False Then
Err.Raise 1001, "Must be a number"
Else
m_MyInteger = NewValue
End If
End Property

Also remember that Property Get must have one less arguement than the cooresponding Let/Set procedure:

Property Get MyInteger() as Integer
MyInteger = m_MyInteger
End Property

Hope that's what you're looking for!

-Mike Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
I get an error because when it goes into the initialize section of the activex there is no value in the variable! I want the value to be from the properties of the activex.

But it doesn't let me get to the property because it displays an error.

That make any sense? s-)

Cheers again.
 
Hmmmm...I don't think the property would return a value anyway. That's because if the initialize is running, the component is still in the process of being created. You need to initialize your component level variables in the initialize event, so that your properties can return the correct value to the calling code. I think if you need one of these values to be initialized based on the value of another property, put that code in the other Property Let procedure instead. For example, if you want the width of an object to be updated based on the size of the picture, update it in the Property Let(Set) instead of the initialize routine:

Private m_picMain as PictureBox
Private m_Width as Integer

Sub Class_Initialize
m_Width = 0
...
End Sub

Property Set picMain(ByVal NewPic as PictureBox)
m_PicMain = NewPic
m_Width = NewPic.ScaleWidth
End Property

Does that sound right? Hopefully that's what you're looking for.

-Mike

Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
If you want the Properties to Persist, you need to use the PropertyBag to Read and Write the changes. This will cause the property to retain its value when you access it next.

Here's some code. Hope it helps:

Code:
'Default Property Values:
Private Const mdef_Selected = False

'Private Property storage
Private m_Selected As Boolean

Public Property Get Selected() As Boolean
    Selected = m_Selected
End Property

Public Property Let Selected(ByVal New_Selected As Boolean)
    m_Selected = New_Selected
    
    'Code goes here to interact with your control
    ShowSelectedLines m_Selected

    'Save the Property to the Property Bag
    PropertyChanged "Selected"
End Property


'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
    m_Selected = mdef_Selected
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    m_Selected = PropBag.ReadProperty("Selected", mdef_Selected)
    ShowSelectedLines m_Selected
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("Selected", m_Selected, mdef_Selected)
End Sub
 
I can't seem to get either of these methods to work. Let say i want a properties field named "TableName".

By using the Property Bag? how would i write the value from the property field "TableName" and then retrieve THAT value when the control is up and running?

Thanks for all your help!

Mel
 
Cheers for that, i've got it working now :)

Does anyone know if its possible to give the property field on the activeX a drop down menu to choose a value from???
 
If you want your Property to display possible values while coding, you can use an Enumeration for your property. It's really simple to do. This should allow the Auto-Syntax Drop-down while typing as well as the drop-down while setting properties on the Property Panel.

Code:
Public Enum dmDataMode
    dmMode1 = 0
    dmMode2 = 1
    dmMode3 = 7
    dmAnyMode = AnyConstant
End Enum

Public Property Get DataMode() As dmDataMode
    ....
Public Property Let DataMode(newValue As dmDataMode)

Drider
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top