DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links