Assigning a TextBox Control via a Class Property


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Assigning a TextBox Control via a Class Property

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Location
    Jacksonville, FL
    Posts
    17

    Question Assigning a TextBox Control via a Class Property

    Hi everyone,

    Another cry for help from someone lost in the wilderness...

    I have a class that defines a TextBox as a property, along the lines of:

    Private WithEvents JunkBox As TextBox
    Public Property Get BoxData() As TextBox
    Set BoxData = JunkBox
    End Property

    Form_Load creates an instance of the class, and uses the Set Property to assign an existing TextBox on the form to the newly-created object:

    Private Sub Form_Load()
    Dim m_Object As clsClass
    Set m_Object = New clsClass

    With m_Object
    Set .BoxData = txtTextBox
    End With
    End Sub

    Stepping through the code, I access the various properties and methods of the class, so I know the form "sees" the class. However, the assignment of the text box control from the form to the object doesn't work. txtTextBox is set to "" when I try to Set .BoxData. How do I get the class/object to recognize the TextBox control?

    Thanks in advance for your help!
    -- Miles

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try changing your BoxData property to:
    Code:
    Public Property Set BoxData() As TextBox
        Set BoxData = JunkBox
    End Property
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Miles,
    you wrote a read-only property (that is, Get only), you must add the Set:

    public property Set BoxData(txt as TextBox)
    set JunkBox = txt
    end property

    Marco
    PS:watch out for circular references!
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center