Chapter 1 Mr. Wangler. Visual Basic is used to create Windows, Web, and command line applications....
-
Upload
luke-rodgers -
Category
Documents
-
view
222 -
download
0
Transcript of Chapter 1 Mr. Wangler. Visual Basic is used to create Windows, Web, and command line applications....
Chapter 1Mr. Wangler
Visual Basic is used to create Windows, Web, and command line applications.
An applicationapplication makes the computer a useful tool by enabling the user to perform a task, such as word processing.
Buttons, check boxes, and text boxes are common objects in a Windows application.
Visual Basic language is an object oriented programming language
Objects – appear on the screen (buttons, check boxes, ….)
Performing tasks with objects is the basis of an OOP application.
A Windows application is event-driven.
Event-Driven application – executes code in response to events.
Event – can occur when the user interacts with an object, such as clicking a button.
Project – contains all files required to execute an application.
Design Window (Form) – displays the application interface where objects are added, deleted, and sized.
Toolbox – contains controls that are used to create objects.
Solution Explorer Window – is used to switch between the Design and Code Window
Properties Window – lists the properties of a selected object.
Properties – defines its appearance, behavior, position, and other attributes.
A Windows application interface includes at least one form.
A form is a graphical object that contains a title bar, a system menu, and Minimize, Maximize, and Close buttons.
A new Visual Basic Windows application automatically includes on Form object.
A Form object has properties just like a tool that define its appearance, behavior, position, and other attributes.
The Text property of a form defines what is displayed in its title bar.
Pressing Enter or clicking outside the Properties window applies the new Text property value to the Form.
The Toolbox in Visual Basic contains controls.
Control – is used to add objects to a form.
Control Objects – display information or get user input.
Name – identifies a control for the programmer. It is good programming style to begin Label object names with lbl.
Text – is the text displayed in the label. Font – controls the font style and size of
the text. Text Alignment – is the alignment of text
in a label.
For most objects, the Name property should always be set to a descriptive name. A proper name begins with the appropriate prefix and then describes the purpose of the object.
Following proper naming conventions is GOOD PROGRAMMING STYLE.
After the first time selecting Save from the File menu or clicking on the Save button will save your project.
An application should be saved frequently to avoid losing changes.
To run an application click the Start button (Play button) on the toolbar or select Start from the Debug menu.
To terminate a running application, click the Stop Debugging button or select Stop Debugging from the Debug menu.
Running an application means that a program is first converted to a language the computer understands in a process called compiling.
Prefix for Main Menu: mnu
Windows applications typically include menus that contain commands.
A menu is modified in the Design window by clicking a MenuItem object and typing a new name.
Applications contains sets of instructions called program code.
Program Code – tells the computer how to perform tasks.
Each line of code is called a statement. In Visual Basic some code is automatically
generated for a form and the objects on the form.
Procedure - is a block of code written to perform specific tasks.
Event Procedure – is a type of procedure that performs tasks in response to user interaction with an object.
Assignment Statement – used in a procedure to change a value at run time.
One use of assignment statements is to set an object property at run time.
Object.Property = Value
Object = the control object name
Property = the name of a property for that object
Value = is a valid property setting
A dot(.) is required between Object and Property to access the property.
The equal sign (=) assigns the property on the left of the equal sign the value on the rights of the equal sign.
Assignment Statements allow a single label to display different text at run time.
When a dot (.) is typed in a statement, an AutoList of options is displayed.
The options displayed in an AutoList depend on what was typed just before the dot.
Me is used in the assignment statement so that object names are displayed when a dot is typed. Me refers to the Form object.
Selecting from an AutoList can reduce typing errors in code. AutoList is also a good way to choose values in an assignment statement.
A group of radio buttons is often used in an application to enable the user to choose from a set of options.
Name = prefix = rad Text = text displayed next to the button Checked = can be set to either True or
False to display the radio button as selected or not.
Only one radio button in a group can be checked at any given time. Therefore, changing the Checked value of one button to True automatically changes the other buttons in the group to False.
The click event procedure executes when the user clicks a button.
A GroupBox is used to group related radio buttons.
A GroupBox object must be added to a form before adding RadioButton objects. Radio buttons are then added to the group box by clicking the RadioButton control and the clicking the group box.
Dragging a group box moves it and all the controls within it together.
Name = prefix = grp Text = is the text displayed at the top of
the group box.
Comments are used to explain and clarify program code for other programmers. Comments have no effect on the way an application runs.
The single quotation mar (‘) must begin a comment. Anything after the single quotation mark is considered a comment for that line of the program only.
Multiline comments can be created by placing a quotation mark at the beginning of each line.
Comments are good programming style and should be used wherever code may be confusing.
Visual Basic.NET includes a set of built-in arithmetic operators for:
Exponentiation (^) Multiplication (*) Division (/) Addition (+) Subtraction (-)
Arithmetic operators are used to form a numeric expression.
A numeric expression is not enclosed in quotation marks because quotation marks indicate text.
Since a label displays text, the value is automatically converted to text.
Visual Basic evaluates a numeric expression using a specific order of operations, or operator precedence.
1. Exponentiation 2. Multiplication and Division 3. Addition and Subtraction
Two operators of the same precedence, for example + and -, are evaluated in order from left to right.
The operators within parentheses are evaluated first.
It is good programming style to include parentheses when there is any confusion or question about the numeric expression.
The button is commonly used in Windows application interfaces.
Name = prefix = btn Text = is the text displayed on the button A click event procedure is usually coded for
a Button object and executes when the user clicks the button.