Chapter 1 Mr. Wangler. Visual Basic is used to create Windows, Web, and command line applications....

32
Chapter 1 Mr. Wangler

Transcript of Chapter 1 Mr. Wangler. Visual Basic is used to create Windows, Web, and command line applications....

Page 1: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

Chapter 1Mr. Wangler

Page 2: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 3: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

Visual Basic language is an object oriented programming language

Objects – appear on the screen (buttons, check boxes, ….)

Page 4: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 5: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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

Page 6: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

Properties Window – lists the properties of a selected object.

Properties – defines its appearance, behavior, position, and other attributes.

Page 7: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 8: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 9: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

The Toolbox in Visual Basic contains controls.

Control – is used to add objects to a form.

Control Objects – display information or get user input.

Page 10: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 11: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 12: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 13: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 14: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 15: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 16: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 17: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 18: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

Object.Property = Value

Object = the control object name

Property = the name of a property for that object

Value = is a valid property setting

Page 19: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 20: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 21: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 22: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 23: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 24: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 25: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 26: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 27: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

Visual Basic.NET includes a set of built-in arithmetic operators for:

Exponentiation (^) Multiplication (*) Division (/) Addition (+) Subtraction (-)

Page 28: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 29: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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

Page 30: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 31: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.

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.

Page 32: Chapter 1 Mr. Wangler.  Visual Basic is used to create Windows, Web, and command line applications. application  An application makes the computer a.