Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.

Similar presentations


Presentation on theme: "Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012."— Presentation transcript:

1 Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012

2 2 Objectives After studying this chapter, you should be able to: Define some of the terms used in object-oriented programming Create, start, and end a Visual Basic 2012 Windows application Manage the windows in the integrated development environment (IDE) Set the properties of an object Manipulate controls

3 3 Objectives (cont’d.) Manipulate controls Use label, button, and picture box controls Use the options on the FORMAT menu Write Visual Basic code Save, close, and open a solution Run a project’s executable file Write an assignment statement Print an application’s code and interface

4 Visual Studio 2012 Visual Basic 2012 is an object-oriented programming language (OOP) Object: anything that can be seen, touched, or used Class: a pattern used to create an object Instance: an object created from a class; object is said to be instantiated Integrated Development Environment (IDE): Contains all the tools and features needed to create, run, and test programs 4

5 5 Visual Studio 2012 (cont'd.) Application: program or suite of programs Windows-based application: Has a Windows user interface Runs on a personal computer 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

6 The Development Cycle 6

7 Phase 1 – Analyze Requirements Verify the requirements are complete Make the initial determination that it is possible to solve the problem using a program List input and output data required Determine whether the input data is available for testing Ensure that the information provided explains how to convert the input data into output data so that a solution, or algorithm, can be developed 7

8 Phase 2 – Design Solution Develop a logical model that illustrates the sequence of steps you will take to solve the problem Objects are smaller pieces of a program Object model Attributes Methods 8

9 Phase 2 – Design Solution Flowcharts graphically represent the logic used to develop an algorithm Control structures, included in flowcharts, allow the programmer to specify the code that will execute only if a condition is met Pseudocode expresses the step-by-step instructions using keywords and depicts logical groupings or structures using indentation 9

10 10

11 11 Control Structures 11

12 12 Pseudocode 12

13 Phase 3 – Validate Design Validate, or check, the program design Step through the solution with test data Compare the program design with the original requirements 13

14 Phase 4 – Implement Design Write the code that translates the design into a program Create the user interface Create comments, or notes, within the code that explains the purpose of the code Test the code as it is written 14

15 Phase 5 – Test Solution Test plan Test cases Integration testing Boundary values 15

16 Phase 6 – Document Solution Includes the requirements documents, program design documents, user interface documents, and documentation of the code Code should be archived electronically 16

17 17 Creating a Visual Basic Windows Application Windows applications consist of solutions, projects, and files Solution: a container that stores projects and files for an entire application Project: a container that stores files associated with a specific portion of the solution A solution may contain one or more projects

18 18

19 19

20 The Windows Form Designer Window Windows Form Designer window: Allows you to create (design) the GUI Graphical user interface (GUI): What the user sees and interacts with Windows Form object (or form): Foundation for the user interface Add other objects such as buttons/text boxes to form Title bar with caption and Minimize, Maximize, and Close buttons Tab at top of designer window has Form1.vb [Design] 20

21 The Windows Form Designer Window (cont’d.) 21

22 22 The Solution Explorer Window Solution Explorer window: Displays a list of projects contained in this solution Displays the items contained in each project

23 23 The Solution Explorer Window (cont'd.) Source file A file containing program instructions Code Program instructions Form file A file containing code associated with a Windows form Give each form file a meaningful name using the Properties window

24 20 The Properties Window Properties A set of attributes that determine an object’s appearance and behavior Properties window Displays properties of the selected object Default property values are assigned when an object is created

25 Properties of a Windows Form 25

26 26 Properties of a Windows Form (cont'd.) Class definition Block of code that defines the attributes and behaviors of an object All class definitions are contained in namespaces Namespace: Defines a group of related classes Dot member access operator The period that separates words in an object’s name to indicate a hierarchy of namespaces

27 27 Properties of a Windows Form (cont'd.) Name and Text Properties Assign meaningful names to forms and use a naming convention Pascal case First letter of each word in the name is uppercase First part of name is object’s purpose Second part of name is object’s class Text property Controls the caption displayed on form’s title bar

28 28 Properties of a Windows Form (cont'd.) StartPosition property Determines the form’s position on the screen when application starts Font Property General shape of characters in text Recommended font is Seqoe UI font Size Property Two numbers separated by a comma and a space The first number represents the object’s width, and the second number represents its height

29 29 The Toolbox Window Toolbox Contains objects that can be added to other objects, such as a form Each tool has an icon and a name to identify it Each tool represents a class from which objects, called controls, can be created 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

30 30 The Toolbox Window (cont’d.)

31 31 The Toolbox Window (cont’d.) 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

32 Using the Format Menu Format menu: provides options for manipulating controls on the form First control selected is the reference control Its size/position is used to adjust the others 32

33 The Code Editor Window Events: User actions while program is running Examples: clicking, double-clicking, scrolling Event procedure: Set of instructions to be processed when an event occurs Tells the object how to respond to an event Code editor window: Used to enter event procedure’s code 33

34 34 The Code Editor Window (cont'd.) Class statement Used to define a class Class Name list box Lists the names of objects (controls) included in the user interface Method Name list box Lists the events to which the selected object is capable of responding Syntax Rules of the language

35 35 The Code Editor Window (cont'd.) Event code template has a procedure header and a procedure footer Begins with keywords Private Sub Procedure name includes object name and event name Handles clause indicates for which objects’ events this code will execute Keyword A word with special meaning in a programming language Sub procedure Block of code that performs a task

36 The Code Editor Window (cont'd.) 36

37 37 The Code Editor Window (cont'd.) Me.Close() instruction Closes the current form at run time If the current form is the only form, the application is terminated Me keyword: refers to the current form Method Predefined VB procedure that can be invoked (called) when needed Sequential processing Each line is executed in sequence Also called a sequence structure

38 38 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

39 39 Starting and Ending an Application (cont'd.) When you start a VB application, the IDE creates an executable file Executable file Can be run outside of Visual Studio 2012 Has a file extension of.exe Stored in the project’s bin\Debug folder

40 40 Assigning a Value to a Property During Run Time Properties window is used to set property values at design time Assignment statement Assigns a value to a variable or property of a control Used to set property values at run time 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

41 41 Assigning a Value to a Property During Run Time (cont’d.)

42 42 Assigning a Value to a Property During Run Time (cont’d.)

43 Syntax Errors Bug An error in a program’s code Debugging The process of locating and correcting bugs in a program Syntax error Occurs when you break one of the programming language’s rules Most syntax errors are caused by typing errors Rest the mouse pointer on the mistyped instruction to see details about the error 43

44 Syntax Errors (cont’d.) Syntax errors should be corrected before starting an application If you start an application with a syntax error, a dialog box appears Click No to open the Error List window 44

45 Programming Tutorial 1 45

46 Programming Tutorial 2 46

47 Programming Example 47


Download ppt "Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012."

Similar presentations


Ads by Google