Visual Basic Concepts

Form Description

The form description starts with a Begin statement and ends with an End statement. The syntax of the Begin statement is:

BeginVB.{Form|MDIForm} formname

The End statement determines where the form description ends and the set of form attributes begins. Without the End statement, Visual Basic tries to read the attributes as if it were describing controls and properties of the form, thus producing errors.

Between the Begin Form and End statements are the properties of the form itself, followed by descriptions of each control on the form. Figure A.2 shows the nested structure of the form description in greater detail.

Figure A.2   Nested structure of the form description

Control Blocks

A control block consists of the text in the form description that defines the properties of an individual control. Like the form description itself, control blocks start with a Begin statement and end with an End statement. The syntax for a Begin statement of a control block is as follows:

Begincontrolclass.controltypecontrolname

The properties for the control appear between the Begin statement and the End statement.

Control-Block Order

The order of the control blocks determines the z-order of the controls. Z-order is a relative ordering that determines how controls overlap each other on a form. The first control in the form description establishes the bottom of the z-order. Controls that appear later in the form description are higher in the z-order and therefore overlap controls that are lower in the z-order.

Embedded Control Blocks

Some controls can contain other controls. When a control is contained within another control, its control block is embedded in the control block of the container. You can embed control blocks inside:

  • Frames

  • Picture boxes

  • Menus

  • Custom controls, depending on their purpose

Embedded controls are commonly used to place option buttons inside a frame. Visual Basic must have all the information necessary for a container before adding any contained controls, so properties for a control must come before any embedded control blocks. Visual Basic ignores any properties within a control block that appear after embedded control blocks.

Menu controls must appear together at the end of the form description, just before the Attributes section begins. When Visual Basic encounters a menu control during the loading of an ASCII form, it expects to find all the menu controls together. Once it detects a nonmenu control following one or more menu controls, Visual Basic assumes there are no more menu controls on the form and ignores any other menu controls it encounters during the loading of that form.

Shortcut Keys

Shortcut keys are keys you use to activate a menu control. The ASCII form uses the same syntax as the SendKeys statement to define key combinations: "+" = SHIFT, "^" = CTRL, and "{Fn}" = function key where n is the key number. Alphabetic characters represent themselves. Shortcut key syntax is:

Shortcut = ^{F4}' <CTRL><F4>

Note   Top-level menus cannot have a shortcut key.

For More Information   See "SendKeys Statement."

Comments in the Form Description

You can add comments to the form description. The single quotation mark (') is the comment delimiter.

Caution   Comments and formatting in the form description are not retained when you save the form in Visual Basic. However, comments and indents in the code section of the form file are preserved.