UserControl Let/Get Property as Object
Here's my goal:
Code:
Option Explicit
Private m_txt As TextBox
Public Property Let txt(new_txt As TextBox)
Set m_txt = new_txt
End Property
Public Property Get txt() As Object
Set txt = m_txt
End Property
Now,... i have tried everything but have not be able to figure out how to:
1. get this Property ("txt") to VB's "Properties" box and
2. get list of all TextBox-es on a Form where my UC is located into "Properties" box where "txt" Property is now shown (from 1.; if possible).
Hope this makes sence.
Re: UserControl Let/Get Property as Object
You use Property Set instead of Property Let :)
Re: UserControl Let/Get Property as Object
Quote:
Originally Posted by Merri
You use Property Set instead of Property Let :)
That doesn't do anything.
Re: UserControl Let/Get Property as Object
Oh, and both properties must use the same type, ie. Object. You can't use TextBox and Object mixed together.
Re: UserControl Let/Get Property as Object
Yeah, I know. It was a typo :blush:
They are both the same. It still doesn't work.
Re: UserControl Let/Get Property as Object
Humm, I managed to miss the last part of the first post, so now I know what you're trying to do. Nope, you can't get a list to VB IDE properties window. It isn't very easy, I've read of some way to do it but it sounded like it would be just an extra dependency mess.
The best you can do is to define Txt as String, then validate there is a textbox of that same name in ParentControls.
Code:
Option Explicit
Private m_Txt As String
Public Property Get Txt() As String
Txt = m_Txt
End Property
Public Property Let Txt(ByVal NewValue As String)
Dim Ctl As Object
NewValue = LCase$(NewValue)
For Each Ctl In ParentControls
If TypeOf Ctl Is TextBox Then
If LCase$(Ctl.Name) = NewValue Then
m_Txt = Ctl.Name
PropertyChanged "Txt"
Exit For
End If
End If
Next Ctl
End Property
Private Sub UserControl_Initialize()
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Dim Ctl As Object, NewValue As String
NewValue = LCase$(PropBag.ReadProperty("Txt", vbNullString))
For Each Ctl In ParentControls
If TypeOf Ctl Is TextBox Then
If LCase$(Ctl.Name) = NewValue Then
m_Txt = Ctl.Name
Exit For
End If
End If
Next Ctl
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Dim Ctl As Object, NewValue As String
NewValue = LCase$(m_Txt)
For Each Ctl In ParentControls
If TypeOf Ctl Is TextBox Then
If LCase$(Ctl.Name) = NewValue Then
PropBag.WriteProperty "Txt", Ctl.Name
Exit For
End If
End If
Next Ctl
End Sub
Re: UserControl Let/Get Property as Object
Thanks, but that approach is already known to me :)
Can you post the link where have you read about it?
Re: UserControl Let/Get Property as Object
Nope, it is quite a long time ago. Another suggestion that I could give is to use a property page, so you can make a combobox or whatever you want yourself.