Sei sulla pagina 1di 20

Visual Programming

BY SHAFIA LECTURER COLLEGE OF COMPUTER SCIENCE & INFORMATION STUDIES

Programming Languages-Procedural, Event Driven and Object Oriented


ProceduralCobol, Fortran, Basic

Program specifies exact sequence of all operations

Event Driven (VB 6.0 and previous)

Contain some elements of Object oriented programming but not all


User controls sequence Click event Double Click event Change event

Object Oriented Programming (OOP) (VB .NET)

VB is an object-oriented programming language. Means you work with objects in building an application. Examples: Form objects, Button objects, TextBox objects, Label objects, ListBox objects, PictureBox objects, and more.

VB is also termed an event-driven programming language because you will write program code that responds to events that are controlled by the system user. Example events include: Clicking a button or menu. Opening or Closing a form. Moving the mouse over the top of an object such as a text box. Moving from one text box to another.

The Object Model


In VB you will work with objects, which 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


Color or size of a Form Typical methods include Close, Show and Clear User clicks a button, User moves a form

Properties equate to Adjectives

Methods are like Verbs

Events occur when the user takes action

The Object Model


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

Terminology Object Property

Definition A thing like a noun in English. Examples include forms and controls you place on forms such as buttons, text boxes, and icons. Objects have properties like adjectives in English. Properties describe object behaviors. Examples of properties include Text, Name, BackColor, Font, and Size. Refer to a property by the notation ObjectName.PropertyName (use the .dot notation) example: TotalDueTextBox.Text or AccountLabel.ForeColor.

Method

Like a verb in English these are the actions that objects exhibit. Examples include methods to Show and Hide forms and methods to Print and Close forms. Refer to a method with the notation ObjectName.MethodName example Me.Close will close the current form. Events are actions usually triggered by the system user such as clicking a button; however, events can also be triggered by the actions of objects. For example, closing a form can trigger an event. This is a really abstract term it is a sort of template for an object. For example, all forms belong to the Form class of object. All buttons belong to the Button class of object. Classes include definitions for object properties, methods, and associated events. Each class is assigned an identifying namespace within the .NET Framework Class Library. Each new object you create is defined based on its class the new object is called a class instance.

Event

Class

Object Model Analogy


Class = automobile Properties = make, model, color, year Object = each individual car

Object is also an Instance of the automobile class

Methods = start, stop, speedup, slowdown Events = car arrives, car crashes

Visual Studio .NET


Included in Visual Studio .NET 2002, 2003,2005,

2008 and onword


Visual Basic Visual C++ Visual C# (C sharp) Visual J# .NET 2.0 Framework or more Standard Professional Enterprise Developer Enterprise Architect Express

Visual Studio .NET Editions


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)

consists of various tools including: Form Designer Editor for entering code Compiler Debugger Object Browser Help facility

The IDE Initial Screen


The Visual Studio IDE with the Start Page open, as it first appears in Windows XP, without an open project.

IDE Main Window

Toolbars Document Window Form Designer Solution Explorer Window Properties Window Toolbox Help

Modes
Design Time--used when designing the user interface

and writing code Run Time--used when testing and running a project Break Time--if/when receiving a run-time error or pause error

Writing Visual Basic Project


There is a three-step process when writing a Visual Basic applicationyou set up the user interface, define the properties and then create the code Planning 1. Design the User Interface 2. Plan the Properties 3. Plan the Basic Code; follow the language syntax rules; use pseudocode (English expression or comment describing action) then you move on to Programming (and use the same three step process) 1. Define the User Interface 2. Set the properties 3. Write the Basic code

VB Application Files
One Solution Filethink of

one solution file equals one project


Solution User Options File Form Files Resource File for the Form

.sln .suo .vb .resx

Project Files
Project User Options File Application configuration File

.vbproj
.vbproj.user .app.config

Remark Statement
Also known as Comment, used for documentation;

every procedure should begin with a remark statement providing explanation Non-executable Automatically colored Green in Editor Begins with an apostrophe ( ' )

On a separate line from executable code At the right end of a line of executable code

`Display your information

Notation
Used to reference object's properties and events in

code

Object dot Property

Form.Text, TextBox.Text Form.Hide( ), TextBox.Focus( )

Object dot Event

To reference an object's events use an underscore

instead of a dot

Button_Click, ListBox_TextChanged

Naming Rules and Conventions


Visual Basic automatically assigns a value to the Name property of each control, for example, Label1, Label2, Label3, or TextBox1, TextBox2, TextBox3, or Button1, Button2, Button3. However, it is difficult to remember the difference between Label1 and Label2 so: if you are going to later refer to the controls, it is best to rename them to a more meaningful name, if you are not going to refer to the controls later, then just use the assigned default name such as Label1. When you name an object such as a Label or TextBox or Button, you must follow these rules: An object name can begin with an alphabetic letter or the special underscore character. An object name can include letters, digits, and underscores. An object name CANNOT include a space or a punctuation mark. An object name CANNOT be a VB reserved word such as Button, Close, or TextBox. An object name can contain a VB reserved word object names such as PrintButton, CloseButton, NameTextBox, and MajorTextBox are legal names.

Pascal naming convention


The rules are: Begin an object name with an uppercase alphabetic character. Capitalize each word that is part of an object name. Select object names that are meaningful. Append the full name of the control class to the end of the name. Avoid abbreviations unless they are standard abbreviations such as SSN (social security number). Examples of valid names: MajorTextBox, ResetButton, MessageLabel, TotalDueTextBox, and CloseButton.

Camel Casing and Hungarian naming conventions


Camel Casing and Hungarian Naming Conventions
Control Type and Camel Casing Naming Suffix TextBox Button Label Example Camel Casing Control Names Hungarian Naming Prefix txt btn Example Hungarian Control Names

NameTextBox, MajorTextBox ShippingButton, ExitButton, ResetButton

txtName, txtMajor btnShipping, btnExit, btnReset lblName, lblOutput

NameLabel, OutputLabel lbl

Note: Label controls are often not renamed they are not referred to later in writing computer code so the default assigned name is unchanged.

Potrebbero piacerti anche