KeyUp Event Examples VB Help

Const DatelnputKey – vbkeyFS
Const TimelnputKey – vbkeyF6
Const SpeciallnputlKey – vbkeyF7
Const Speciallnput2Key – vbkeyF8
{more code} .

Notice the definitions of the constants that make the code easier to read and simplify
its maintenance.
, .
With a little.additional effort, you can provide users with a dialog box that lets them assign their own strings to functionkeys. You l! probably have to take into consideration the status of the Shift argument, which reports the status of the Shift,Control, and Alt keys (see Table 5.1). Wmdows already uses ‘many o f the function keys and you shouldn’t reassign them. For example, the Fl key is the standard . Wmdows context-sensitive Help key, and users will be confused if they press Fl and see the date appearin their documents.

To find out whether another Shift key is down when a key is pressed, use the AND operator with the Shift argument. The following If structure detects the Shift key:

If Shift AND vbShiftMask

Then {Shift key was down}

End If

To detect combinations of the Shift keys, use statements such as this one: If (Shift AND vbShiftMask) AND (Shift AND vbA1tMask) Then  {Shift and A1t keys were down}

The ListBox and ComboBox Controls

The ListBox and ComboBox controls present lists of choices for the user to select. The ListBox control occupies a user-specified amount of space on the Form and is populated with a list of items; the user can select one or more with the mouse. The items  must be inserted in the Listbox control through the code, or via the List property in the Properties window. Each new item in the List property must be entered on a separate line. To change lines, press Control+Enter, When you’re done entering items, press Enter and.the Items will appear ~ the ListBox control On the Form. Users can’t enter data in a list;,they can only select-items, which will be manipulated by the application when they click a button or take some other action. The ComboBox controla1so contains multiple items but occupies less space . on the screen. The Combobox control is an expandable ListBox control: the user can expand it to make a selection and retract it after the selection is made. The real advantage to the Combo Box control, however, is that the user can enternew information in the ComboBox, rather than being forced to select only the  items listed.

.The ListBox and ComboBox Controls

The ComboBox control may seem more useful, but its use isn’t as common as ListBox controls. This section first examines the Listbox control’ s properties and methods. Later, you’ll see how the same properties and methods can be used with the ComboBox control

Basic properties

The ListBox and ComboBox controls provide a few properties that can be set only at design time. Because they determine the basic ~ctiona1ity of the control and can’t be changed at runtime, we’ll start with these fundamental properties.

MultiSelect

This property determines how the user canselect the list’s items and must be set atdesign time (at runtime, you can only read this property’s value ). The MultiSeled. property’s values determine whether the user can seled’multiple tems and which method will be Used for inultiple selection. The possible values of MultiSelect property.

Sorted

Items can be inserted b.y the application into a ListBox or ComboBox control, but inserting them in the proper place and maintaining some sort of organization can be quite a task for the programmer. If you want the items to be always sorted, set the control’s Sorted property to True. This property must be set at design time and is read-only at runtime.
The ListBox control is basically a text control and won’t sort numeric data property. True  the ListBox control to sort numbers, you must first format them with leading zeros. For example, the number 10 will appear in front of the number 5, because the string “10” is smaller than the string “5”. If the numbers are formatted as “005”, they will be sorted correctly. The items in a sorted ListBOxcontrol are in ascending and case-sensitive order. Moreover, there is no mechanism for changing this default setting.

Uppercase characters appear before the equivalent lowercase characters, but both upper- and lowercase characters appear together. All words beginning with B appear after the words beginning with A and before the words beginning with C. Within the group of words beginning with B, those beginning with B appear before those beginning with b.

Style

This property determines the appearance of the control. Its value can be 0 (Standard) or 1 (Checkbox). The two lists shown in Figure’ 5.6 illustrate the Standard and Checkbox appearance of the ListBox control. Notice that the list on the left is unsorted and the list on the right is sorted.

Posted on November 4, 2015 in Basic ActiveX Controls

Share the Story

Back to Top
Share This