Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

 

'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 View Plain Text
Download Demo Project Not Available
View Code Online Not Available





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.