August 20, 1997

In-Line Code

Calling a function or procedure incurs some overhead. If you have atwo-line function that is called from only three places, you might considerputting those three lines in the functions themselves and not make thema function. This can save some processing time. This could lead to somefuture maintenance problems, however. Here

Use Specific Object Types

When passing controls as parameters, make the function that is receivingthe parameter accept the specific object type instead of generic types.The exception to this is when multiple types of objects may be passed intoa routine. In these cases, you must test for the object type within theroutine. Specific object types

Set AutoRedraw to False

If AutoRedraw is set to True, VB keeps a bitmap of the form in memorythat it uses to redraw the form after another window in front of it isclosed. Because this consumes memory, set AutoRedraw to False if you arenot using any graphics methods. Most business applications can have AutoRedrawset

Use VB’s Timer Function to Optimize Code

I often see questions in the VBPJ forum about comparative speedsfor different methods of performing actions in code. In many cases, a simplegeneralization of which is fastest cannot be made. VB’s Timer function,however, allows testing your code as you go. Declare a Single variable,TStart! and use this line at the

Clear Out Data When Unloading Forms

When unloading a form, use the following piece of code behind a Closebutton: Unload This code should also be put in the Form_Unload() event handlerfor that form: Set = Nothing This clears out any remaining code/data in the data segment forthe form, if you don’t do it explicitly. This is

Use Read-Only Attributes When Sharing Code

If you set a VB file’s DOS attribute to read-only, VB will show itwith a red lock in the project window and prevent it from being overwritten.This is a handy way of sharing a common code library between developers’projects and ensuring that no one can modify the “common” code.

Hide and Show the Scroll Bar in a Multiline Text Box

Have you ever wanted to make that pesky scroll bar disappear when itis not needed, and reappear when the text exceeds the viewable area ofthe text box? Setting the scroll bar properties at run time won’t do it.You could use API calls, but how do you decide when the lines

Saving the Position of a Designer Widgets’ Dockable Toolbar

The best way to save information about an application’s options, suchas toolbar positioning, is to write the settings to an INI file. To doso, two Windows API functions must be used: GetPrivateProfileInt and WritePrivateProfileString.Here are two functions that load and save settings to and from an INI file: ‘These two

Using ALT+F4

Pressing Alt and F4 will close any window with a control box. Becauseyou can’t choose Alt and F4 as a shortcut key combination from the menudesigner, you must place it as part of the caption property if you wantto tell the user that this will close the window.

No more posts to show