June 18, 1999

Watch How You Use Your Booleans

With the introduction of the Boolean data type in VB4, you might be tempted to convert it to a numeric value using the Val function for storage in a database table. Watch out! Val won’t convert a Boolean into -1 (or 1) as you might expect. Use the Abs or

Numeric Conversion of Strings

When dealing with numerics and strings, be advised of a couple “gotchas.” The Val() function isn’t internationally aware and will cause problems if you have users overseas. But you can’t just blindly switch to CLng, CInt, and so on, which are internationally aware. These functions don’t support an empty string

Simplify Boolean Variable Updates

Instead of using an If construct to set a Boolean variable, you can assign a Boolean variable to the result of any logical comparison. For example, instead of this code: If MyNumber > 32 Then BooleanVar = TrueElse BooleanVar = FalseEnd If Use this code: BooleanVar = (MyNumber > 32)

Limit Selected Check Boxes With Collection Logic

Use the Count property to determine exactly how many controls are loaded. You can also use the For Each loop to perform code on each control. For instance, if you have a control array of check boxes and you don’t want more than three checked, use this code: Private Sub

SQL Trick to Join Multiple Select Statements

Don’t overlook the UNION keyword in SQL as a way to simplify selections from multiple tables. For instance, to select the customer with the highest sales from three tables with basically the same layout, use the UNION keyword to allow your VB code to open only one resultset with the

Hunt for Developers

Want to see a list of the developers who worked on VB5 and VB6? Try this: From VB’s View menu, select Toolbars, then Customize…. In the resulting dialog, click on the Commands tab. In the Categories list, select Help. Select “About Microsoft Visual Basic” in the Commands list, and drag

Keypress Won’t Fire When Pasting Into Text Box

Don’t put rules for validating text values or formats in the KeyPress event-use the Change event instead. If you “paste” into a text box, the KeyPress event isn’t fired and all your validation goes out the window. Also, if you don’t carefully put code in the Change event that sets