devxlogo

December 9, 1998

Set the ListIndex Without the Click Event

If you set the ListIndex property of a list-box or combo-box control, VB might generate an unwanted Click event. Instead of writing code to bypass the Click event, use SendMessage

Clearing the Contents of a String

To explicitly erase the contents of a string object, you can use the member function erase(): void f(){ char key; string msg = “press any key to continue”; cout

ReDim the Right Array!

Many VB programmers use the Option Explicit statement to make sure each variable has been explicitly declared before using it. This means you’ll always notice a misspelled variable, which if

Cleaning up After a Crash

If your app uses temporary files, store the file name(s) in the Registry as you create them. When you exit the program, delete the temporary file and its related Registry

How to Access the Topmost Element of a Stack

You can access the topmost element (the one pushed the latest) of a stack container by using the member function top(): #include #include #include using namespace std;void main() { stack

Type-o-matic Text Box

This code creates a smart input box. Every time you type something into this text box, the first letters of your string are compared against the members of a hidden

Viewing bool Variables as Literals

By default, iostream objects display bool variables as 0 and 1. You can override the default setting by inserting the formatting flag boolalpha to the object stream. Consequently, the symbolic

Two Flavors of dynamic_cast<>

The operator dynamic_cast comes in two flavors: one uses pointers and the other uses references. Accordingly, dynamic_cast returns a pointer or a reference of the desired type when it succeeds.

MessageBox Advantage

You’ve probably noticed that the display time stops when an application pops up VB’s built-in MsgBox. Although the system timer continues to tick, the timer control isn’t updated every second,