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 to set the ListIndex without generating the event. Call the SetListIndex function below, passing the list (either a list box

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 not caught might cause your application to behave erratically. However, when you use the ReDim statement (documented, albeit ambiguously), Option

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 entry. However, if you shut off the machine, Windows crashes, or your program crashes, your temporary file will stay in

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 strstack; strstack.push(“Bjarne”); strstack.push(“Stroustrup”); string topmost =; // topmost element is “Stroustrup” cout

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 list box. The code guesses how your string should be completed and finishes it for you, similar to how the

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 representations ‘false’ and ‘true’ will be displayed instead: #include using namespace std;void main() { bool b = true; cout

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. When dynamic_cast cannot perform the cast, it returns a NULL pointer, or in case of a reference, it throws a

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, nor do other events (such as painting) process. To update the timer, replace VB’s built-in MsgBox with the MessageBox API

No more posts to show