'Accessing Textbox Methods through Object Variable
Q. This is what I`m trying to do:
Dim a As TextBox
Set a = Text1
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
This is the mouse down method for a text box. I want to use this method through
the variable a. I`ve been told I`d need to use inheritance, and
polymorphism.
A. You do not need inheritance and polymorphism here. As long as the variable
has visible scope within the module with the Text1_MouseDown event, you can use
that variable to call the TextBox it references. Modify your code like this:
'In the Form's declaration section
Private a As TextBox
'In the Form_Load event
Set a = Text1
Then, anywhere within that form, including Text1_MouseDown, you can do this...
a.Text = "Put new text here"
anytime you want to change Text1`s content. Incidentally, if you declare a as
public:
Public a As TextBox
Then you can also refer to a outside of the form using Form1.a assuming the form
containing Text1 is Form1.
Thanks to: Taiwo Ayedun
Downloads
In IE right-click and select 'Save Target As...' or in Netscape
right-click and select 'Save Link As...'
View Plain Text
Not Available
Not Available