dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language:
Expertise: Beginner
Aug 6, 1997

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


An Improved User Tip

The User Tip submitted by Nick Bulka in the January 1996 issue of VBPJ was interesting, but, as with so much code, improvable:

 
Sub TextHiLite( t as TextBox )
                t.SelStart = 0
                t.SelLength = len(t)
End Sub




My improvement is to pass the TextBox control as a parameter. When VB passes a control as a parameter, it passes the Reference to it, not a copy of it. With the Reference available, you can change the properties and so forth without the time and resource overhead of declaring and instantiating a new object. Besides, it could be appropriate to change some characteristic for a control that does not have the focus. By passing it as a parameter, the programmer is not restricted to the active control.

VB3 can be lax about cleaning up after its objects. Several VBPJ articles suggest doing clean-up. This little routine I put in all my <form>_Unload events really helps keep the resources in check:

 
                If <object_variable> Is _
                        Nothing then
                Else
                                Set <object_variable> = _
                                        Nothing
                End If



This modification is for database result-set (tables, dynasets, and so forth) objects. The code is more straightforward to create and to read with an empty 'Then' section and going right to Else:

 
                ' It's time to close the object:
                If <object_variable> Is Nothing _
                        Then
                Else
                                .<object_variable>.Close
                                Set <object_variable> = _
                                        Nothing
                End If



Richard A.
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date