devxlogo

We are an award-winning tech entrepreneurship website where trusted experts can provide value globally.

Since 1998, DevX has helped people start businesses, build websites, and provide enterprise technology to people globally. Interviewing the likes of Microsoft’s co-founder, Steve Ballmer, the publication brings comprehensive, reliable, and accessible insights to the Internet.

devxlogo

Trusted for 26 years

Over 30K Articles

1M+ Readers

Expert-reviewed

10K+ Tech Terms

As seen in:

microsoft logo
business_insider_logo
wired_logo
berkley
arstechnica_logo
hackernoon

The Latest

Avoid the Outline Control

The Outline control might at first seem very usable. Well, it isn’t.Apart from the arcane interface, it’s almost guaranteed to blow up yourapp if it’s running on a “nonstandard” video

Tips on Using Boolean Logic

Programmer’s of all skill levels often make errors when using Booleanlogic. This statement might not evaluate the way you think it should: IF (SomeNumber AND 16) OR _ (SomeOtherNumber 0)

Always Use These

Always use Option Explicit: it draws immediate attention to variabletypos. Always use Save As Text: files are less easily corrupted, more easilyrecovered, and editable by a text editor other than

Clearing the Contents of a Datagrid

If the DataGrid is bound to a VB data control, you need to set theRecordSource property of the data control to “” (null string)and then use the Refresh method: Sub

Troubleshooting Erratic VBX Behavior

If a VBX is acting erratically, make sure you are using the most currentversion of the VBX on your system (and make sure to put it into your user’sWindows/System directory

Easy-to-Implement Status Bar with Spyworks

The SBCEasy custom control that comes with Desaware’s SpyWorks-VB canbe used to update a status bar whenever the mouse moves over any controlor form in your application. All you need

Menu Status on MDI Forms with Spyworks-VB

Many features of SBCEasy (a tool that comes with Desaware’s SpyWorks-VB)work only on its container, and because it cannot be placed on a MDI Parentform, the MenuSelect event does not

Eliminate Dead Code

Be sure to remove functions or procedures that you are no longer using.If you delete a control, be sure to remove the event procedures that weretied to that control.

Set ClipControls Property to False

Setting the ClipControls property to False significantly reduces thetime it takes forms to paint. The default is True, so you’ll need to changeit to False. If you’re using graphics methods,

Shorten Control and Form Names

Keep control and form names as short as possible. Such names are keptin the EXE file. Variable names, however, are not kept in the EXE.

Editing Grid Cells

Grids provide a nice way to present certain types of spreadsheet information.Unfortunately, the grid in VB does not allow editing. With just a littlebit of code you can simulate editing

VB Assist Quick Tips

Using the AutoSave feature in the VBAssist Options box automaticallysaves changes made to your project after a defined time interval. To temporarily bypass VBAssist’s Control Lock feature, hold down theCtrl

Toggle Boolean Values Using Not

To toggle a variable between True and False, use the Not operator insteadof an If statement. Use the Not operator on those variables you have explicitlyset with the True or

Setting Tab Stops in List Boxes

To quickly set tab stops in list boxes, use the SendMessage API call.The units used are called Dialog Base Units, which average out to aboutfour per character. Some experimentation is

Use the Controls Collection

If you need to reference every control on a form, using the Controlscollection will be faster than referencing every control directly. Forexample, if you have four command buttons on a

Preventing “Invalid Use of Null” Errors

If your app uses database or other functions that can return Null variants,your app will crash sooner or later with that dreaded “Invalid Useof Null” error. Preventing it is simple:

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

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

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

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.

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

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

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