Professional Documents
Culture Documents
Visual Basic Controls
Visual Basic Controls
? Standard Visual Basic Controls Control Control Name Button CheckBox Name Prefix chk Function Example in
Displays or enables input of Assignment 2 a two-part choice, such as VB Controls Yes/No or True/False. Enables the user to select an entry from a list or enter a new value. Enables the user to initiate a program action. Can include an icon, caption, and ToolTips. Assignment 3 VB Controls Assignment 1 in VB Controls
ComboBox
cbo
in
CommandButton
cmd
dat dir
Provides a link to database files. Displays and enables a user Assignment 1 in to choose from available VB Programming subdirectories on a drive. Displays and enables a user to choose from available disk drives on the computer. Displays and enables a user to choose from available files in a directory. Serves as a container for other controls. Provides a method for grouping controls. (To group controls in a frame, select the frame with a single-click first, then draw a control in it.) Produces a numerical value based on the scroll bar's horizontal position. Displays a graphic image. Similar in appearance to the picture control but with different functionality. Displays text that the user Assignment 1 in VB Programming
DriveListBox
drv
FileListBox
fil
Frame
fra
hsb
img
Assignment 1 in VB Programming
Label (lbl)
lbl
Assignment 4
in
Visual Basic Controls cannot directly modify. VB Controls Displays lines on the form. Displays a list of items Assignment 3 from which the user can VB Controls select one or more entries. Provides you with a way to link to OLE servers. Displays or enables a choice among multiple items. (Also known as a radio button.) Displays a graphic image. It can also serve as a container for other controls Displays geometric shapes on the form. Displays text that the user can edit. Assignment 4 VB Controls Assignment 2 VB Controls in
Line ListBox
lin lst
ole opt
in in
PictureBox (Pic)
Pic
Assignment 1 VB Controls
in in
vsb
Provides a means for an Assignment 5 action to be taken after VB Controls passage of a certain amount of time. Same as above but vertical. Note the scrollbars behave like standard Windows scrollbars.
Figure 2
Figure 3
? Control Array
Suppose you have a form with 100 command buttons and they all accomplish pretty much the same task -- they print their caption to a label control. Now what would be better; to draw 100 command buttons and name them btnPrint1 through btnPrint100, or should you find a better way to do it? In this scenario you would undoubtedly use a control array. A control array is exactly what the name implies -- an array of controls. So instead of 100 different names, you would have btnPrint(1) through btnPrint(100).
(ii)
Notice that the indexes start from 0 and go to 4, but the captions indicate the button's number is one greater than it's index. This is taken into account when we write code for the controls. (iii) All the controls in a control array share the same code, and each event of a control in a control array is passed the control's index. So this index argument can be used in the code, as is shown below: Sub btnControl_Click (Index As Integer) lblNotice = "You selected button " & Str$(Index + 1) End Sub
Note: We're just setting the caption of lblNotice to indicate which button we pushed. We add one to Index because the first index is 0, and the caption of the first button indicates that it is number 1. So we take this into account by adding one to the index.