Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Expertise: Beginner
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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
                                Set <object_variable> = _
                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 _
                                Set <object_variable> = _
                End If

Richard A.
Comment and Contribute






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



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