Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Add properties to intrinsic Visual Basic Controls

Posted on 2003-02-26
9
Medium Priority
?
337 Views
Last Modified: 2013-11-26
I am wanting to add a property to the standard Visual Basic textbox.  I can add properties to forms by defining Property Get/Let/Set functions in the form's module.  But it would seem that the same approach can't be applied to textboxes and other intrinsic VB controls because these don't have associated code modules.

To assist in explaining this problem, let me use an example.  I want to add a property called "Abc" to a textbox.  How do I do it?  I need to be able to set/get hte property value using syntax such as:

Text1.Abc = "Hello World"

Any ideas?



0
Comment
Question by:austaz
8 Comments
 
LVL 5

Expert Comment

by:Julian_K
ID: 8024502
Hello, austaz.

I think the only way to do this is by creating a new OCX control, based on the textbox control.
But before doing this you should consider if it is possible to use another approach. For example using some function and the .tag property of the textbox, etc.
0
 
LVL 6

Expert Comment

by:marconovaro
ID: 8024591

This is another way: you create a class, and declare inside it somethin like this:

Private WithEvents m_TxtBox as TextBox

Public Sub Init( myTxtBox as TextBox )
    set m_TxtBox = myTxtBox
End Sub

Then, in your form code, you shall use it setting the reference to a textbox that you want.
In this way, you'll be able to add properties and functions to the class, that will be a "wrapper" for your original textbox. Furthermore, inside the class you can receive events from the textbox and use them, like in a normal form.

You can have a look here

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=38711&lngWId=1
(it's a piece of code of mine)

to understand what I mean.
Hope this helps,
M.



0
 
LVL 1

Expert Comment

by:sazhagianambi
ID: 8024622
Hi,

This Can Be Done Using AcitvexControls. So You Just use Normal Text Box as Your New Control. Click addProcedure (Avail in Tools Menu) Method , Set Name as abc and Select Type as Property.

It Will Generate the Get/let  Functions for abc Property.Place the Code You Wanted Under Them.

Regards,
Nambi
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:austaz
ID: 8029411
Thanks for the responses....

The concern I have about idea of using an ActiveX control is that I would have to create properties within the user control to map to all the existing properties of the textbox.  Plus there would need to be code added so that when the activeX control was resized the textbox inside was resized.

marconovaro's suggestion is OK except sometimes I would need to refer to properties using the code like m_TxtBox.text and other times code like mytextboxclass.Abc.  I really need to be able to reference both normal and added properties using the same object.

The use of the tag property is OK but I need to add a lot of properties.  So, short of have a delimited tag value, that's not really feasible.



0
 
LVL 5

Expert Comment

by:Julian_K
ID: 8031548
Well, sad to say it, but there is no easier approach.

Regards,
Julian.
0
 
LVL 6

Accepted Solution

by:
marconovaro earned 600 total points
ID: 8031594

To reply your question, if you want to access the normal properties of the textbox, you can do like this.
In the class module, define

Property Get TextBoxRef() As TextBox
    Set TextBoxRef = m_TxtBox
End Property

Now, you can access the textbox, reffering to the class:

myClass.TextBoxRef.Text = "This is a test. :)"

Otherwise, if you want a "single" object that has the properties of the textbox, plus your own ones, you'll have to follow Julian_K suggestion: create a new OCX!

Hope this helps.
M.
0
 

Expert Comment

by:CleanupPing
ID: 8901092
austaz:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8972944
Moderator, my recommended disposition is:

    Accept marconovaro's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question