Results 1 to 8 of 8

Thread: UserControl Let/Get Property as Object

  1. #1

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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.

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: UserControl Let/Get Property as Object

    You use Property Set instead of Property Let

  3. #3

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  5. #5

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: UserControl Let/Get Property as Object

    Yeah, I know. It was a typo

    They are both the same. It still doesn't work.

  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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

  7. #7

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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?

  8. #8
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width