programming languages—procedural, event driven, and object oriented

17
Programming Languages—Procedural, Event Driven, and Object Oriented Procedural—Cobol, Fortran, Basic Program specifies exact sequence of all operations. Event-Driven Programming(VB 6.0 and previous) Contain some elements of object-oriented programming, but not all Object-Oriented Programming (OOP) (VB .NET) User controls sequence Click event Double Click event Change event

Upload: shawna

Post on 11-Jan-2016

43 views

Category:

Documents


2 download

DESCRIPTION

Programming Languages—Procedural, Event Driven, and Object Oriented. Procedural—Cobol, Fortran, Basic Program specifies exact sequence of all operations. Event-Driven Programming(VB 6.0 and previous) Contain some elements of object-oriented programming, but not all - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Programming Languages—Procedural,  Event Driven, and Object Oriented

Programming Languages—Procedural, Event Driven, and Object Oriented

• Procedural—Cobol, Fortran, Basic

• Program specifies exact sequence of all operations.

• Event-Driven Programming(VB 6.0 and previous)

• Contain some elements of object-oriented programming, but not all

• Object-Oriented Programming (OOP) (VB .NET)

• User controls sequence

–Click event

–Double Click event

–Change event

Page 2: Programming Languages—Procedural,  Event Driven, and Object Oriented

The Object Model

In VB, you will work with objects that have properties, methods, and events. Each object is based on a class.

• Objects equate to Nouns.– Forms are windows.– Controls are components contained inside a form.

• Properties equate to Adjectives.– Color or size of a Form

• Methods are like Verbs.– Typical methods include Close, Show and Clear

Page 3: Programming Languages—Procedural,  Event Driven, and Object Oriented

Object Model Continued

• Events occur when the user takes action.– User clicks a button, User moves a form

• Classes are templates used to create a new object.– Classes contain the definition of all available properties,

methods, and events.– Each new object created is based on a class.

• Creating three new buttons makes each button a instance of the Button class.

Page 4: Programming Languages—Procedural,  Event Driven, and Object Oriented

An Object Model Analogy

• Class = automobile

• Properties of automobile class= make, model, color, engine, year

• Object = Each individual auto is an object.– Object is also an Instance of the automobile class.

• Methods = start, stop, speedup, slowdown

• Events of automobile class = Turn Wheel, Press Brake

Page 5: Programming Languages—Procedural,  Event Driven, and Object Oriented

Visual Studio .NET

• Included in Visual Studio .NET 2010• Visual Basic• C# (C sharp)• J# (J sharp)• F# (F sharp)• .NET 3.5 Framework (Base Class Library)• Common Language Runtime (CLR)

• All languages compile into a common machine language: MSIL (Microsoft Intermediate Language)

• Visual Studio .NET Editions: Express, Standard, Professional, Ultimate

• Get your own Professional Edition at www.dreamspark.com

Page 6: Programming Languages—Procedural,  Event Driven, and Object Oriented

Visual Basic Creates Graphical User Interfaces

Text boxes

Check box

ButtonsPicture box

Radio buttons

Label

Message box

You can create both windows and web apps.

Page 7: Programming Languages—Procedural,  Event Driven, and Object Oriented

Visual Studio Environment

The Visual Studio environment is where you create and test your projects. In Visual Studio, it is called an Integrated Development Environment (IDE) consisting of various tools including:

• Form Designer• Editor for entering and modifying code• Compiler• Debugger• Object Browser• Help Facility

Page 8: Programming Languages—Procedural,  Event Driven, and Object Oriented

IDE Main Window

Document window

Properties window

Solution Explorer

Page 9: Programming Languages—Procedural,  Event Driven, and Object Oriented

The Tool Box

You select objects from the toolbox (controls) to create your user interface.

By default, the toolbox is auto-hidden on the far left of the screen, but you can change that.

Page 10: Programming Languages—Procedural,  Event Driven, and Object Oriented

VB Application Files

• Solution File— usually one solution file equals one project: HelloWorld.sln

• Solution User Options File: HelloWorld.suo

• Form Files: HelloForm.vb

• Resource File for the Form: HelloForm.resx

• Form Designer: HelloForm.Designer.vb

• Project User Options File: HelloWorld.vbproj.user

Once a project is run, several more files are created by the system. The only file that is opened directly is the solution file.

Page 11: Programming Languages—Procedural,  Event Driven, and Object Oriented

Writing Visual Basic Projects

There is a three-step process when writing a Visual Basic application:

– set up the user interface, – define the properties– create the code.

Page 12: Programming Languages—Procedural,  Event Driven, and Object Oriented

Your First Visual Basic.NET Example

Create an application that displays a form with a field for entering your name.

Two buttons are also displayed on the form:

– when the first button is clicked, display a

label that says: Hello, name.– when the second button is clicked, exit the

program

Page 13: Programming Languages—Procedural,  Event Driven, and Object Oriented

Creating the Code

• While the project is running, the user can perform actions.

• Each action by the user causes an event to occur.

• Write code for the events you care about.

• Code is written as event procedures, usually as an object method: Example: Me.Close()

Methods always have parentheses; properties never do.

• VB will ignore events for which you do not write code.

Page 14: Programming Languages—Procedural,  Event Driven, and Object Oriented

Naming Conventions in Your Code

• Use meaningful names: orderForm, not form1

• Have a set of standards and always follow them!!!

• No spaces, punctuation marks, or reserved words

• Some example conventions:

– Pascal Casing: MessageLabel, ExitButton

– Camel Casing: messageLabel, exitButton

– Industry: lblMessage, btnExit

Page 15: Programming Languages—Procedural,  Event Driven, and Object Oriented

Documenting Your Code: The Remark Statement

• Also known as a comment, it is used for documentation; every procedure should begin with a remark statement providing explanation.

• It is non-executable

• Automatically colored green in code editor

• Begins with an apostrophe ( ' )

• On a separate line from executable code

• At the right end of a line of executable code

'Display the Hello World message.

Page 16: Programming Languages—Procedural,  Event Driven, and Object Oriented

Debugging Finding and Fixing Errors

• Syntax Errors• Breaks VB’s rules for punctuation, format, or spelling• Smart editor finds most syntax errors, compiler finds the rest.• The editor identifies a syntax error with a squiggly blue line and

you can point to an error to pop up the error message.• You can display the Error List window and line numbers in the

source code to help locate the error lines.

• Run-Time Errors• Statements that fail to execute, such as impossible arithmetic

operations

• Logic Errors• Project runs, but produces incorrect results.

Page 17: Programming Languages—Procedural,  Event Driven, and Object Oriented

Visual Basic Help

• Help displays in a separate browser window.

• Microsoft Developer’s Network (MSDN) is the primary source of help documentation.

• Access MSDN at http://msdn.microsoft.com

• Context-sensitive help is also available by pressing the F1 key.