Search
Left Quote    A clever person solves a problem. A wise person avoids it.
- Einstein    
Right Quote
 
[login] | [Register]
 

Getting Started with VB 6.0

by: bs0d
Page: 7 of 9
(View All)

Menus, Combo Boxes and QB Color


Menu - A drop-down list of items displayed below a menu name on the screen from which you selected one item.


In both Windows and VB, a menu consists of a menu bar with menu names, each of which drops down to display a list of menu commands. You can use menu commands in place of or in addition to the command buttons to activate a procedure.


Menu commands are actually controls and have events and properties. Each menu command has a Name property and a Click event, similar to a command button. To create a menu for your form, you will use the Visual Basic Menu Editor, which accessible by pressing < CTRL > + E or Click on Menu Editor Icon.


PARTS OF THE MENU:


Caption - Holds the words you want to appear on the screen.

Name - Indicates the name of the menu control and what the control is referred to by the program. When naming, start out with the prefix, "mnu" . For example, if you had a menu control for "file", you would name it, "mnuFile"

SUBMENU - A list of commands that appear underneath a menu command, (a menu within a menu). To create a submenu, press the right arrow key to move to the next level.

Menu List Box - Shows the list of all menu items that have been created and the indication levels. You can move up, down, left and right by clicking on the name of the menu item and then clicking on one of the four arrow buttons.

Separator Bars - A horizontal line that separates one menu from another. To define a separator bar, type a single hyphen ( - ) for the caption and give it a name. Even though you can never reference the separator bar in the code, you still have to give it a name. If you have more than one separator bar, each one has to have a unique name. (mnuSep1, mnuSep2, ...ect.)

Shortcut Keys - You can create a keyboard shortcut key for a menu item when its created. Select a shortcut key for your menu item by selecting it from the list provided. The purpose of the shortcut is to provide an alternative to sorting through menus to perform a single task.

Checked - If you want a check mark to appear next to an item in your menu, you would put a check here. Check marks are normally for options that you want to be toggled on and off.

Enabled - If you want the user to be able to select a menu item, this will be checked. By default, all are enabled. If unchecked, this menu item will be dimmed out. You can also change this property in the actual code (mnuStar.Enabled = False).

Visible - Determines whether a menu item is displayed on the screen or not. If there is a check in this check box, the menu item will be displayed on the screen. If the box is not checked, the menu item will not be displayed. This property can also be changed in the actual code (mnuStar.Visible = True).

Insert - Click on this if you want to insert an item into the middle of a menu. The item will be inserted at the location of the current item. All items below that point will be moved down.

Delete - Will delete the highlighted menu. Cancel will close the menu editor without saving changes, and OK will save changes to the menu and close the menu editor.


COMBO BOXES


Combo Box - A type of control used to hold a list of items from which the user selects one from a pull down menu.



Differences between a List Box and a Combo Box:


  • With a list box, there is no pull down menu, users scroll through the list using scroll bars and selects the item of his/her choice. With a combo box, the user clicks on a down arrow, a pull down menu is displayed and the user chooses by clicking one on the list.
  • You can type your own entry into the list with a combo box. With a list box, you cannot type in your own entries.

Like list boxes, items can be added to a combo box in two ways...

  • Using the List property
  • Using the AddItem method

ADDING ITEMS TO THE LIST USING THE LIST PROPERTY:


  1. Scroll through the properties window to the LIST property
  2. Click on the down arrow to drop down an empty list
  3. Type your first item and press < CTRL > < ENTER >
  4. Continue entering items as indicated in 3 until finished
  5. Press < ENTER > or click outside of list box to complete operation.

ADDING ITEMS TO THE LIST USING THE ADDITEM PROPERTY:


  1. Double click on the form to open FORM_LOAD
  2. Enter your items using the below format:

< object_name > .AddItem " < Value > "

ADDING ITEMS INTO THE ItemData ARRAY:


< object_name > .AddItem " < Value > "
< object_name > .ItemData(< object_name > .NewIndex) = < Value >

ADDING ITEMS TO THE LIST:


The code below will add items into the list of a Combo Box:


Harvard will have the index of 0, Yale of 1 and so on

Entering Items into the ItemData array of a Combo Box...


TEXT PROPERTY:



The Text property refers to the actual item that is currently selected in the list.

< label > = < control > .Text


ListIndex works as the same as List Boxes. Same as NewIndex, ItemData, Sorted, Clear, RemoveItem, ListCout...ect.


When naming Combo Boxes, use the prefix, "cbo". For example, if you wanted a combo box named School, you would name it, cboSchool.


QB COLOR


QBCOLOR - is a built-in function in VB that will display 15 different colors. The QBCOLOR function has one argument, which is the index of the color to be displayed. The index can range from values 0 to 15. What the heck, here are the values for you:


-Index-
-Color-
0
Black
1
Blue
2
Green
3
Cyan
4
Red
5
Magenta
6
Yellow
7
White
8
Gray
9
Light Blue
10
Light Green
11
Light Cyan
12
Light Red
13
Light Magenta
14
Light Yellow
15
Bright White

Example: