Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.

Similar presentations


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

1 Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008

2 Microsoft Visual Basic 2008: Reloaded, Third Edition2 Objectives After studying this chapter, you should be able to: Define the terminology used in programming Create a Visual Basic 2008 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

3 Microsoft Visual Basic 2008: Reloaded, Third Edition3 Objectives (continued) Enter code in the Code Editor window Save a solution Start and end an application Print an application’s code and interface Write an assignment statement Close and open an existing solution Find and correct a syntax error

4 Microsoft Visual Basic 2008: Reloaded, Third Edition4 Programmers Programs: directions given to computers Programmers: people who write programs Typical tasks performed by a programmer include: –Analyze a problem statement or project specification –Plan an appropriate solution and convert the solution to instructions that the computer can follow Programmers should be able to: –Think logically and pay attention to detail –Be patient and persistent, and able to work under pressure –Be creative in designing solutions and testing them

5 Microsoft Visual Basic 2008: Reloaded, Third Edition5 Programming Languages Programming languages: used to communicate with the computer Object-oriented programming language: a language that allows the programmer to use objects to accomplish a program’s goal Object: anything that can be seen, touched, or used –Every object is created from a class Class: a pattern or blueprint used to create an object Visual Basic is available as a stand-alone product (Express Edition) or as part of Visual Studio 2008

6 Visual Studio 2008 Integrated Development Environment (IDE): –Contains all the tools and features needed to create, run, and test programs –Includes an editor and compiler Visual Studio 2008: –IDE used to create Windows- or Web-based programs –Includes Visual Basic 2008, Visual C++ 2008, and Visual C# 2008 Microsoft Visual Basic 2008: Reloaded, Third Edition6

7 7 Visual Studio 2008 (continued) Application: program or suite of programs Windows-based application: –Has a Windows user interface –Runs on a desktop 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

8 Microsoft Visual Basic 2008: Reloaded, Third Edition8 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 piece of the solution A solution may contain one or more projects

9 Microsoft Visual Basic 2008: Reloaded, Third Edition9 Solutions, Projects, and Files (continued) Figure 1-1: Illustration of a solution, project, and file

10 Microsoft Visual Basic 2008: Reloaded, Third Edition10 Starting Microsoft Visual Studio 2008 Figure 1-2: How to start Microsoft Visual Studio 2008

11 Microsoft Visual Basic 2008: Reloaded, Third Edition11 Figure 1-3: Visual Studio 2008 Professional Edition startup screen

12 Creating a Visual Basic 2008 Windows-Based Application Microsoft Visual Basic 2008: Reloaded, Third Edition12 Figure 1-4: How to create a Visual Basic 2008 Windows-based application

13 Microsoft Visual Basic 2008: Reloaded, Third Edition13 Figure 1-5: Completed New Project dialog box

14 Microsoft Visual Basic 2008: Reloaded, Third Edition14 Figure 1-6: Solution and Visual Basic Project created by Visual Studio 2008

15 Microsoft Visual Basic 2008: Reloaded, Third Edition15 Managing the Windows in the IDE Figure 1-7: How to manage the windows in the IDE

16 Microsoft Visual Basic 2008: Reloaded, Third Edition16 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 when using the application Windows Form object (or form): –Adds other objects such as buttons and text boxes to the form to create the GUI –Has a title bar with caption and Minimize, Maximize, and Close buttons –Tab at top of designer windows has [Designer]

17 Microsoft Visual Basic 2008: Reloaded, Third Edition17 Figure 1-8: Windows Form Designer window

18 Microsoft Visual Basic 2008: Reloaded, Third Edition18 The Solution Explorer Window Solution Explorer window: –Displays a list of projects contained in this solution –Displays the items contained in each project Figure 1-9: Solution Explorer window

19 Microsoft Visual Basic 2008: Reloaded, Third Edition19 The Solution Explorer Window (continued) 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

20 Microsoft Visual Basic 2008: Reloaded, Third Edition20 The Properties Window Properties: a set of attributes that determine an object’s appearance and behavior Properties window: displays properties of selected object Default property values are assigned when an object is created

21 Microsoft Visual Basic 2008: Reloaded, Third Edition 21 The Properties Window (continued) Figure 1-10: Properties window showing the properties of the Form1.vb file

22 Microsoft Visual Basic 2008: Reloaded, Third Edition22 The Properties Window (continued) Properties window includes an Object box and a Properties list Object box: –Located immediately below Properties window title bar –Contains the name of the selected object 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

23 Microsoft Visual Basic 2008: Reloaded, Third Edition23 Properties of a Windows Form Figure 1-11: Windows form properties listed in the Properties window

24 Microsoft Visual Basic 2008: Reloaded, Third Edition24 Properties of a Windows Form (continued) 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 Name property: used to refer to an object in code –Give each object a meaningful name Hungarian notation: naming convention using three or more character prefix to represent the object type

25 Microsoft Visual Basic 2008: Reloaded, Third Edition25 Properties of a Windows Form (continued) 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 StartPosition property: determines the form’s position on the screen when application starts Font: general shape of characters in text –Recommended font is Seqoe UI font Point: a measure of font sizes; one point = 1/72 inch

26 Microsoft Visual Basic 2008: Reloaded, Third Edition26 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 an object, called a control Controls: –Objects displayed on a form –Represented as icons in the toolbox –Can be locked in place on the form

27 Microsoft Visual Basic 2008: Reloaded, Third Edition27 The Toolbox Window (continued) Figure 1-12: Toolbox window

28 Microsoft Visual Basic 2008: Reloaded, Third Edition28 The Toolbox Window (continued) Figure 1-13: How to add a control to a form

29 The Toolbox Window (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition29 Figure 1-14: How to manipulate the controls on a form

30 Microsoft Visual Basic 2008: Reloaded, Third Edition30 The Label Control Label control: –Displays text that user cannot edit –Used as “prompts” to explain controls or display output –Name should end with “Label” Control names use camel case Camel casing: 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

31 Microsoft Visual Basic 2008: Reloaded, Third Edition31 The Label Control (continued) Figure 1-15: Wizard application’s user interface

32 Microsoft Visual Basic 2008: Reloaded, Third Edition32 The Button Control Button control: –Performs an immediate action when clicked –Its name should end with “Button” Text property: specifies the text that appears on the button’s face

33 The Picture Box Control Picture box control: used to display an image on a form Image property: specifies the image to display SizeMode property: handles how the image will be displayed –Settings: Normal, StretchImage, AutoSize, CenterImage, or Zoom Microsoft Visual Basic 2008: Reloaded, Third Edition33

34 The Code Editor Window Events: user actions while program is running –Examples: clicking, double-clicking, scrolling Event procedure: set of instructions to be executed when an event occurs –Tells the object how to respond to an event Code editor: used to enter programming code Microsoft Visual Basic 2008: Reloaded, Third Edition34

35 The Code Editor Window (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition35 Figure 1-16: How to open the Code Editor window

36 The Code Editor Window (continued) Microsoft Visual Basic 2008: Reloaded, Third Edition36 Figure 1-17: Code Editor window opened in the IDE

37 Microsoft Visual Basic 2008: Reloaded, Third Edition37 The Code Editor Window (continued) Class statement: used to define a class –Begins with Public Class –Ends with End 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 When you select a control from the Class Name list box and a method name, a code template for the event appears in the Code Editor window Syntax: rules of the language

38 Microsoft Visual Basic 2008: Reloaded, Third Edition38 The Code Editor Window (continued) Keyword: a word with special meaning in a programming language Event code template has a procedure header and procedure footer Sub procedure: block of code that performs a task Event’s procedure header: –Begins with keywords Private Sub –Procedure name includes object name and event name –Handles clause indicates for which objects’ events this code will execute

39 Microsoft Visual Basic 2008: Reloaded, Third Edition39 The Me.Close() Instruction Me.Close() instruction: closes the current form at run time –If the current form is the main 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

40 Microsoft Visual Basic 2008: Reloaded, Third Edition40 The Me.Close() Instruction (continued) Figure 1-19: Me.Close() instruction in the Click event procedure

41 Microsoft Visual Basic 2008: Reloaded, Third Edition41 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 Figure 1-20: How to save a solution

42 Microsoft Visual Basic 2008: Reloaded, Third Edition42 Starting and Ending an Application Startup form: the form to be displayed when the application starts Figure 1-21: How to specify the startup form

43 Microsoft Visual Basic 2008: Reloaded, Third Edition43 Starting and Ending an Application (continued) Figure 1-22: Project Designer window

44 Microsoft Visual Basic 2008: Reloaded, Third Edition44 Starting and Ending an Application (continued) Figure 1-23: How to start an application

45 Microsoft Visual Basic 2008: Reloaded, Third Edition45 Starting and Ending an Application (continued) Figure 1-24: Result of starting the Wizard application

46 Microsoft Visual Basic 2008: Reloaded, Third Edition46 Starting and Ending an Application (continued) When you start a VB application, the IDE creates an executable file Executable file: –Can be run outside of Visual Studio 2008 –Has a file extension of.exe –Stored in the project’s bin\Debug folder

47 Microsoft Visual Basic 2008: Reloaded, Third Edition47 Starting and Ending an Application (continued) Figure 1-25: How to end an application

48 Microsoft Visual Basic 2008: Reloaded, Third Edition48 Using an Assignment Statement 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 = symbol

49 Microsoft Visual Basic 2008: Reloaded, Third Edition49 Using an Assignment Statement (continued) Figure 1-26: Assignment statements entered in the Code Editor window

50 Microsoft Visual Basic 2008: Reloaded, Third Edition50 Printing Your Application Figure 1-27: How to print an application’s code and user interface

51 Microsoft Visual Basic 2008: Reloaded, Third Edition51 Closing the Current Solution Closing a solution closes all projects and files in that solution –You are prompted to save any files that have unsaved changes Figure 1-28: How to close a solution

52 Microsoft Visual Basic 2008: Reloaded, Third Edition52 Opening an Existing Solution Only one solution can be open at any one time If a solution is already open, opening a different one will close the currently open solution

53 Microsoft Visual Basic 2008: Reloaded, Third Edition53 Opening an Existing Solution (continued) Figure 1-29: How to open an existing solution

54 Programming Tutorial Microsoft Visual Basic 2008: Reloaded, Third Edition54 Figure 1-46: Result of starting the Wizard application

55 Programming Example Microsoft Visual Basic 2008: Reloaded, Third Edition55 Figure 1-54: User interface

56 Microsoft Visual Basic 2008: Reloaded, Third Edition56 Summary Program: directions given to a computer Object-oriented programs focus on objects to accomplish a task 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 2008 are composed of solutions, projects, and files

57 Microsoft Visual Basic 2008: Reloaded, Third Edition57 Summary (continued) Windows Form Designer window: used to create GUI applications Windows Form object is created from the Windows Form class Solution Explorer window: shows names of projects and files in the solution Properties window: lists an object’s properties and their values All class definitions are contained in namespaces

58 Microsoft Visual Basic 2008: Reloaded, Third Edition58 Summary (continued) System.Windows.Forms namespace contains definition of the Windows Form class and class definitions for objects added to a form Dot member access operator indicates a hierarchy of namespaces 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 Form’s StartPosition property sets the position of the form when it first appears at run time

59 Microsoft Visual Basic 2008: Reloaded, Third Edition59 Summary (continued) Recommended font is Segoe UI in 9-point size Toolbox: contains tools for creating the GUI A control’s Text property value is displayed inside the control 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

60 Summary (continued) Event procedure: the code that tells an object how to respond to an event Use the Class Name and Method Name list boxes to select an object and event to code Code Editor: provides code templates for each object’s event procedures Can display line numbers in the Code Editor window Me.Close() instruction: can terminate an application Microsoft Visual Basic 2008: Reloaded, Third Edition60

61 Summary (continued) You should save your solution every 10-15 minutes When an application is started in the IDE, the computer creates an executable file Use an assignment statement to set a property value at run time Can print your application’s code, with or without line numbers Closing a solution closes all projects and files in it Only one solution can be open in the IDE at any time Microsoft Visual Basic 2008: Reloaded, Third Edition61


Download ppt "Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008."

Similar presentations


Ads by Google