Professional Documents
Culture Documents
Fourth Edition
Objectives
After studying this chapter, you should be able to: Create a Visual Basic 2010 Windows-based application Manage the windows in the Integrated Development Environment (IDE) Set the properties of an object Add a control to a form Use the Label, Button, and PictureBox tools Use the options on the Format menu
Objectives (cont'd.)
Enter code in the Code Editor window Save a solution Start and end an application Print an applications code and interface Write an assignment statement Print an applications code and interface Close and open an existing solution Find and correct a syntax error
User interface: what the user sees and interacts with when using an application Web-based application:
Has a Web user interface Runs on a server Accessed with a computer browser
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 5
Figure 1-2: How to start Visual Studio 2010 or Visual Basic 2010 Express Edition
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 8
10
Figure 1-5: How to create a Visual Basic 2010 Windows application (contd.)
12
13
Figure 1-7: Completed New Project dialog box in Visual Studio 2010
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 14
Figure 1-8: Completed New Project dialog box in Visual Basic 2010 Express Edition
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 15
21
22
23
Properties list:
Left column displays names of properties
Use the Alphabetical or Categorized buttons to sort the display of properties
Settings box: Right column containing the current value of each property
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 24
Figure 1-14: Properties window showing a partial listing of the forms properties
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 25
Namespace: defines a group of related classes Dot member access operator: the period that separates words in an objects name to indicate a hierarchy of namespaces Name property: used to refer to an object in code
Give each object a meaningful name
26
Text property: controls the caption displayed on forms title bar StartPosition property: determines the forms position on the screen when application starts Font: general shape of characters in text
Recommended font is Seqoe UI font
Controls:
Objects displayed on a form Represented as icons in the toolbox
Controls on a form can be selected, sized, moved, deleted, locked in place on the form and unlocked
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 28
Control names use camel case Camel case: lowercase first word; uppercase first letter of each subsequent word in the name Not necessary to assign meaningful names for labels used as prompts because they are never used in code Labels used for output should have meaningful names
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 32
Text property: specifies the text that appears on the buttons face
34
35
Multi-select controls by clicking the first, then using Ctrl-click for each additional control
First control selected is the reference control
Its size/position is used to adjust the others
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 36
37
38
39
Figure 1-21: Code template for the exitButtons Click event procedure
42
44
Saving a Solution
An asterisk appears on the designer and Code Editor tabs if a change was made since the last time the solution was saved
45
48
50
51
String: zero or more characters enclosed in quotation marks Assignment operator: the = sign Value of the expression on the right of the = sign is assigned to the object and property on the left of the = sign
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 52
Figure 1-30: How to print the code and interface during design time
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 54
55
Coding Errors
Bug: an error in a programs code Debugging: the process of locating and correcting bugs in a program Syntax error: occurs when you break one of the programming languages rules
Most syntax errors are caused by typing errors
Rest the mouse pointer on the mistyped instruction to see details about the error
57
58
59
61
Programming Tutorial 1
Programming Tutorial 2
63
Programming Example
64
Summary
Object-oriented programming language allows programmers to use objects to accomplish a goal Object: can be seen, touched, or used and has attributes that control its appearance and behavior Class: a pattern from which an object can be created Applications created in Visual Studio 2010 are composed of solutions, projects, and files Windows Form Designer window: used to create GUI applications
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 65
Summary (cont'd.)
A form is the foundation for the user interface Windows Form object is instantiated from the Windows Form class Solution Explorer window: displays names of projects and files in the solution Properties window: lists an objects properties All class definitions are contained in namespaces System.Windows.Forms namespace contains definition of the Windows Form class and class definitions for objects added to a form
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 66
Summary (cont'd.)
Name property: used to refer to an object in code Text property of a form: specifies the text to be displayed in the title bar of the form and in the taskbar when running Forms StartPosition property sets the position of the form when it first appears at run time Recommended font is Segoe UI in 9-point size Toolbox: contains tools for creating the GUI A controls Text property value is displayed inside the control
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 67
Summary (cont'd.)
Controls on a form can be selected, sized, moved, deleted, or locked at design time Label control: contains text that a user cannot edit Button control: performs an immediate action when clicked Picture box control: displays an image on a form Format menu provides options for aligning and sizing controls on a form Event procedure: the code that tells an object how to respond to an event
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 68
Summary (cont'd.)
Use the Class Name and Method Name list boxes to select an object and event to code Code Editor: provides code templates for each objects event procedures Me.Close() instruction: can terminate an application Computer automatically creates an executable file when you start a Visual Basic application in the IDE Use an assignment statement to assign a value to a property during run time
Microsoft Visual Basic 2010: Reloaded, Fourth Edition 69
Summary (cont'd.)
You should print your applications code and its user interface Closing a solution closes all projects and files in it The process of locating and correcting errors (bugs) in a program is called debugging
70