September 30, 2000

Always use “$-typed” string functions

VB official documentation seems to encourage you to use “$-less” string functions, e.g. Left, LTrim or UCase, instead of their time-honored Left$, LTrim$ and UCase$ counterparts. If you do so, however, you should be aware that the former ones return a variant value that, when used within string expressions, must

Get full control on the text typed in a TreeView’s node

The TreeView control exposes the AfterLabelEdit event to let the programmer validate the text entered in a Node, but there is no way to trap keys as they are typed by the user. This prevents you from discarding unwanted characters while the user types them.You can work around this problem

LenB has changed from VB5 to VB6

Visual Basic stores UDTs in unpacked format, that is it alignes all UDT elements to the double word (except that Integers and Boolean are aligned to the word, and byte elements aren’t aligned at all). To keep the elements aligned VB adds padding bytes where necessary. For instance the structure:

Conversion to proper case

When dealing with proper names, you may want to capitalize the first letter of each word, e.g. convert “john smith” into “John Smith”. Under VB3 you had to write a custom function to do the job, whereas VB4 has introduced the versatile StrConv routine, that does it with just one

Determine whether the app is running on a flawed Pentium CPU

Here’s a simple test that you can use to determine whether the application is running on a system equipped with a Pentium CPU affected by the FDIV bug: ‘ return True if the CPU suffers from the FDIV bugFunction IsBuggedPentium() As Boolean IsBuggedPentium = ((1 / 3221224323) * 3221224323) 1

The behavior of the LostFocus event depends on VB version

The behavior of the LostFocus event has changed in the transition from VB4 to VB5. Under VB4, if a control on a form has the input focus and the user clicks on a toolbar button, the control fires a LostFocus event. Under VB5 and VB6, the same action doesn’t fire

Error Handling and Corrections

The following is an example to handle errors in VB. It combines “On ErrorGoTo” and “On Error Resume Next” to handle all errors (minor orserious ones), as well as attempting to correct errors. It is very similarto the “Try {} Catch {}” structure. For very obvious errors, you may not