Nothing Special   »   [go: up one dir, main page]

Vbnotes 1

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

Code Window Split Bar

Margin Indicator Object list Procedures/Events Box

   

Use the Code window to write, display, and edit Visual Basic code. You can open as many Code
windows as you have modules, so you can easily view the code in different forms or modules, and copy
and paste between them.
You can open a Code window from:
• The Project window, by selecting a form or module, and choosing the View Code button.
• A Form window, by double-clicking a control or form, choosing Code from the View menu, or
pressing F7.
You can drag selected text to:
• A different location in the current Code window.
• Another Code window.
• The Immediate and Watch windows.
• The Recycle Bin.
Window Elements
Object Box
Displays the name of the selected object. Click the arrow to the right of the list box to display a list
of all objects associated with the form.
Procedures/Events Box
Lists all the events recognized by Visual Basic for a form or control displayed in the Object box.
When you select an event, the event procedure associated with that event name is displayed in the Code
window.
If (General) is displayed in the Object box, the Procedure box lists any declarations and all of the
general procedures that have been created for the form. If you are editing module code, the Procedure box
lists all of the general procedures in the module. In either case, the procedure you select in the Procedure
box is displayed in the Code window.
All the procedures in a module appear in a single, scrollable list that is sorted alphabetically by
name. Selecting a procedure using the drop down list boxes at the top of the Code window moves the
cursor to the first line of code in the procedure you select.
Split Bar
Dragging this bar down, splits the Code window into two horizontal panes, each of which scrolls
separately. You can then view different parts of your code at the same time. The information that appears
in the Object box and Procedures/Events box applies to the code in the pane that has the focus. Dragging
the bar to the top or the bottom of the window or double-clicking the bar closes a pane.
Margin Indicator Bar
A gray area on the left side of the Code window where margin indicators are displayed.
Margin indicator
An icon displayed in the Margin Indicator bar in the Code window. Margin indicators provide
visual cues during code editing

Procedure View Icon


Displays the selected procedure. Only one procedure at a time is displayed in the Code window.
Full Module View Icon
Displays the entire code in the module.

Constant
A named item that retains a constant value throughout the execution of a program, as opposed to a
variable, whose value can change during execution. Each host application can define its own set of
constants. Additional constants may be defined by the user with the Const statement. Constants can be
used anywhere in your code in place of actual values. A constant may be a string or numeric literal,
another constant, or any combination that includes arithmetic or logical operators except Is and
exponentiation. For example: Const A = "MyString"
string literal
Any expression consisting of a sequence of contiguous characters surrounded by quotation marks
that is literally interpreted as the characters within the quotation marks.

string expression
Any expression that evaluates to a sequence of contiguous characters. Elements of a string
expression can include a function that returns a string, a string literal, a string constant, a string variable, a
string Variant, or a function that returns a string Variant (VarType 8).

string constant
Any constant (defined using the Const keyword) consisting of a sequence of contiguous characters
interpreted as the characters themselves rather than as a numeric value.

String Function

Returns a Variant (String) containing a repeating character string of the length specified.
Syntax

String(number, character)

The String function syntax has these named arguments:


Part Description
number Required;Long. Length of the returned string. If number containsNull, Null is returned.
character Required; Variant.Character code specifying the character orstring expression whose
first character is used to build the return string. If character contains Null, Null is returned.

Remarks

If you specify a number for character greater than 255, String converts the number to a valid
character code using the formula:

character Mod 256

String Function Example


This example uses the String function to return repeating character strings of the length specified.

Dim MyString
MyString = String(5, "*") ' Returns "*****".
MyString = String(5, 42) ' Returns "*****".
MyString = String(10, "ABC") ' Returns "AAAAAAAAAA".

Number Property

     Returns or sets a numeric value specifying an error. Number is the Err object's default property.
Read/write.

Remarks

When returning a user-defined error from an object, set Err.Number by adding the number you
selected as an error code to the vbObjectError constant. For example, you use the following code to
return the number 1051 as an error code:

Err.Raise Number := vbObjectError + 1051, Source:= "SomeClass"

statement

A syntactically complete unit that expresses one kind of action, declaration, or definition. A
statement generally occupies a single line, although you can use a colon (:) to include more than one
statement on a line. You can also use a line-continuation character (_) to continue a single logical line
onto a second physical line.

Comment

Text added to code that explains how the code works. In Visual Basic, a comment line can start
with either an apostrophe (') or with the Rem keyword followed by a space.

Comment Block and Uncomment Block Commands

Adds and removes the comment character, an apostrophe, for each line of a selected block of text.
If you do not have text selected and you choose the Comment Block or Uncomment Block command, the
comment character is added or removed in the line where the pointer is located.

Comment Block

Adds the comment character to each line of a selected block of text.

Uncomment Block
Removes the comment character from each line of a selected block of text.

End Statement

    Ends a procedure or block.

End

End Function

End If

End Property

End Select

End Sub

End Type

End With

Syntax The End statement syntax has these forms:

Statement Description

End Terminates execution immediately. Never required by itself but may be placed
anywhere in a procedure to end code execution, close files opened with the
Open statement and to clear variables.

End Function Required to end a Function statement.

End If Required to end a block If…Then…Else statement.

End Property Required to end a Property Let, Property Get, or Property Set procedure.

End Select Required to end a Select Case statement.

End Sub Required to end a Sub statement.

End Type Required to end a user-defined type definition (Type statement).

End With Required to end a With statement.

Remarks

When executed, the End statement resets all module-level variables and all static local variables in all
modules. To preserve the value of these variables, use the Stop statement instead. You can then resume
execution while preserving the value of those variables.

Note   The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or
Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and
Terminate events of forms and class modules is not executed. Objects created from class modules are
destroyed, files opened using the Open statement are closed, and memory used by your program is freed.
Object references held by other programs are invalidated.

The End statement provides a way to force your program to halt. For normal termination of a
Visual Basic program, you should unload all forms. Your program closes as soon as there are no other
programs holding references to objects created from your public class modules and no code executing.
Project Explorer window
View Object
Toggle Folders

View Code

List Window

Displays a hierarchical list of the projects and all of the items contained in a project.

Window Elements
View Code
Displays the Code window so you can write and edit code associated with the selected item.

View Object
Displays the Object window for the selected item, an existingform, module, ActiveX object, or
user control.

Toggle Folders
Hides and shows the object folders while still showing the individual items contained within them.

List window
Lists the all loaded projects and the items included in each project.

Project.
The project and items contained within it.

Forms
All .frm files associated with the project.

Modules
All .bas modules for the project.

Class Modules
All .cls files for the project.

User Controls
All user controls for the project.

User Documents
All document objects, .dob files, in the project.

Property Pages
All property pages, .pag files, in the project.

ActiveX Designers
All designers, .dsr files, in the project.

Related Documents
Lists all documents to which you want a pointer. The path to the document is stored rather than the
document itself. When you click View Object, Visual Basic searches the registry for the document type
and executes the appropriate open command. You can place any valid document type in the project.

Resources

Lists all of the resources you have in your project.

Note A check mark to the left of a filename in the Project Explorer indicates that the file is
checked out of a version control project, and currently has read/write status. The check mark is only
displayed if you are connected to a version control program, such as Microsoft Visual SourceSafe, which
is included with the Enterprise Edition of Visual Basic.

Properties window

Object Box

Categorized Tab

Alphabetic Tab

List Window

Description Pane

A window used to display or change properties of a selected form or control at design time. Some
custom controls have customized Properties windows.
Properties Window
Lists the design-time properties for selected objects and their current settings. You can change
these properties atdesign time. When you select multiple controls, the Properties window contains a list of
the properties common to all the selected controls.

Window Elements
Object Box
Lists the currently selected object. Only objects from the active form are visible. If you select
multiple objects, the properties common to the objects and their settings, based on the first object selected,
appear on the Properties List tabs.

Properties List Tabs


Alphabetic Tab — Alphabetically lists all properties for the selected object that can be changed at design
time, as well as their current settings. You can change the property setting by selecting the property name
and typing or selecting the new setting.
Categorized Tab — Lists all properties for the selected object by category. For example, BackColor,
Caption, and ForeColor are in the Appearance category. You can collapse the list so that you see the
categories or you can expand a category to see the properties. When you expand or collapse the list, you
see a plus (+) icon or minus (-) icon to the left of the category name.

Description Pane
Shows the property type and a short description of the property. You can turn the description of
the property off and on using the Toggle Status command on the shortcut menu. You can move through
the list of descriptions by pressing the ARROW keys.

Toolbox

    Displays the standard Visual Basic controls plus any ActiveX
controls and insertable objects you have added to your project.
You can:

 Display ToolTips for the Toolbox buttons by selecting


the Show ToolTips option in the General tab of the
Options dialog box.

 Customize the Toolbox by adding tabs to it.

When you add a tab, a Pointer is always available on it.

 Customize the General tab or a custom tab by adding


controls using the Components command from the
Project menu.

Standard Toolbox Controls

Pointer

The only item in the Toolbox that doesn't draw a control. When you select the pointer, you can only resize
or move a control that has already been drawn on a form.

PictureBox

Displays graphical images (either decorative or active), as a container that receives output from graphics
methods, or as a container for other controls. A PictureBox control can display a graphic from a bitmap,
icon, or metafile, as well as enhanced metafile, JPEG, or GIF files. It clips the graphic if the control isn't
large enough to display the entire image.

 Label

Allows you to have text that you don't want the user to change, such as a caption under a graphic. A
Label control is a graphical control you can use to display text that a user can't change directly.

 TextBox

Holds text that the user can either enter or change. A TextBox control, sometimes called an edit field or
edit control, displays information entered at design time, entered by the user, or assigned to the control in
code at run time.
Remarks

To display multiple lines of text in a TextBox control, set the MultiLine property to True. If a multiple-
line TextBox doesn't have a horizontal scroll bar, text wraps automatically even when the TextBox is
resized. To customize the scroll bar combination on a TextBox, set the ScrollBars property.

Scroll bars will always appear on the TextBox when its MultiLine property is set to True, and its
ScrollBars property is set to anything except None (0).

If you set the MultiLine property to True, you can use the Alignment property to set the alignment of
text within the TextBox. The text is left-justified by default. If the MultiLine property is False, setting
the Alignment property has no effect.

Frame

Allows you to create a graphical or functional grouping for controls. To group controls, draw the Frame
first, and then draw controls inside the frame. A Frame control provides an identifiable grouping for
controls. You can also use a Frame to subdivide a form functionally—for example, to separate groups of
OptionButton controls.

Remarks

To group controls, first draw the Frame control, and then draw the controls inside the Frame. This
enables you to move the Frame and the controls it contains together. If you draw a control outside the
Frame and then try to move it inside, the control will be on top of the Frame and you'll have to move the
Frame and controls separately.

To select multiple controls in a Frame, hold down the CTRL key while using the mouse to draw a box
around the controls.

CommandButton

Creates a button the user can choose to carry out a command. Use a CommandButton control to begin,
interrupt, or end a process. When chosen, a CommandButton appears pushed in and so is sometimes
called a push button.

CheckBox

Creates a box that the user can easily choose to indicate if something is true or false, or to display multiple
choices when the user can choose more than one.

OptionButton

Allows you to display multiple choices from which the user can choose only one.

ComboBox

Allows you to draw a combination list box and text box. The user can either choose an item from the list
or enter a value in the text box.

ListBox

Used to display a list of items from which the user can choose one. The list can be scrolled if it has more
items than can be displayed at one time.

HScrollBar (horizontal scroll bar)

Provides a graphical tool for quickly navigating through a long list of items or a large amount of
information, for indicating the current position on a scale, or as an input device or indicator of speed or
quantity.
 VScrollBar (vertical scroll bar)

Provides a graphical tool for quickly navigating through a long list of items or a large amount of
information, for indicating the current position on a scale, or as an input device or indicator of speed or
quantity.

 Timer

Generates timer events at set intervals. This control is invisible at run time.

Timer control can execute code at regular intervals by causing a Timer event to occur.

Remarks

The Timer control, invisible to the user, is useful for background processing.

You can't set the Enabled property of a Timer for a multiple selection of controls other than Timer
controls.

There is no practical limit on the number of active timer controls you can have in Visual Basic running
under Windows 95 or Windows NT.

 DriveListBox

Displays valid disk drives.

DirListBox (directory list box)

Displays directories and paths.

 FileListBox

Displays a list of files.

 Shape

Allows you to draw a variety of shapes on your form at design time. You can choose a rectangle, rounded
rectangle, square, rounded square, oval, or circle.

Line

Used to draw a variety of line styles on your form at design time.

 Image

Displays a graphical image from a bitmap, icon, or metafile on your form. Images displayed in an Image
control can only be decorative and use fewer resources than a PictureBox.

Data

Provides access to data in databases through bound controls on your form.

OLE

Allows you to link and embed objects from other applications in your Visual Basic application.

You might also like