devxlogo

Tip Bank

Better Alternatives to Macros

Macros in C++ are better avoided. They are unsafe, hard to debug, and may bloat your .exe files. C++ offers significantly better alternatives to them: 1. Function-like macros should be

Before You Resort to Void *…

Void * can serve as a generic data pointer, yet it suffers from the well-known ailments associated with pointers: it can be NULL or a dangling pointer. Furthermore, it usually

Default Template Argument

Like ordinary functions, templates can have default type arguments. A good example is STL’s vector. It actually has two arguments–the second one is an allocator class template. Since an allocator

Let the User Control Long Operations

To allow the user to control long operations, use a single CommandButton to control starting and stopping a looping process: Dim Running As BooleanPrivate Sub CmdStartStop_Click() If Running Then ‘

Pass Parameters to User Dialogs

It’s fairly common practice to add buttons to your date and numeric fields to allow users to select and display a popup calendar or calculator. However, to display a calculator

A Better Way to Swap Two Integer Variables

The algorithm shown in the tip, “Swap Values Using Only Two Variables” [“101 Tech Tips for VB Developers, Supplement to the February 1997 issue of VBPJ, page 25], crashes not

Use Arrays, Not Collections

Arrays take less memory and are faster than collections. If you don’t need to use a collection’s keyed lookup, easy extensibility, and other features, use an array instead.