November 6, 1998

Put an Ampersand (&) in a Menu or Command Button

When creating menus and command buttons, use the ampersand symbol to create a shortcut key for that option. For example, you might use “&Cancel” for a command button with a “Cancel” button used to cancel an event. To create menu options or command buttons with an ampersand in the caption,

Place a Variable-Length String in Text

VB doesn’t have a function to replace part of a string (of n-length) with another string (of x-length). The Mid() statement works only with target and replacement strings of the same length. Use this code to solve the problem: Function ReplaceText( _ ByVal sOriginalString As String, _ ByVal sTargetString As

Add Columns to a Standard VB List Box

Use the Win32 API to set tab stops in a Visual Basic list box by creating these declarations and routine in a module: Public Const LB_SETTABSTOPS = &H192Declare Function SendMessage Lib “user32” _ Alias “SendMessageA” (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, _ lParam

Force Uppercase Characters in a Text Box

To change text in a text box to uppercase as soon as the user types it in, use this code: Private Sub txtname_KeyPress(KeyAscii As Integer) ‘Puts in uppercase as soon as typed KeyAscii = Asc(UCase(Chr(KeyAscii)))End Sub

Register ActiveX Components Manually

Not all ActiveX DLL and OCX files include installation programs to properly register the control. You need to run REGSVR32.EXE manually to perform the registration. You can save time by creating a shortcut in your WINDOWSSENDTO folder called “Register ActiveX Control.” Use the target name of C:WINDOWSREGSVR32.EXE for the shortcut.

Destroying Collections’ Items

Many programmers mistakenly believe they can remove all the items from a collection by setting the collection itself to Nothing: Dim children as New Collection…Set children = Nothing This technique only works if you don’t have another object variable pointing to the same collection. In this case, setting the children