Sunteți pe pagina 1din 63

Visual Programming

BY
SHAFIA
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE

12/24/2019
Brief History of Visual Basic
2

 Evolved from BASIC


 Beginner’s

 All-Purpose

 Symbolic

 Instruction

 Code

 Developed in mid-1960s

12/24/2019
Visual Basic
3

 Evolved into Visual Basic in 1991


 Major Features:
 IDE (Integrated Development Environment)
 GUI’s
 Event Handling
 Object Oriented Programming
 Exception Handling
 Rapid Application Development (RAD)

12/24/2019
VB.Net
4

 Introduced in 2000
 Features:
 Enhance language interoperability

 Availability of Internet features


 Web services
 Enhanced object orientation
 Including library of components
 Platform independence
 Not backwardly compatible

12/24/2019
.Net Strategy
5

 Web Services
 Applications can be used over the Internet
 Includes ASP.Net technology

 Software Reuse
 Allows programmers to concentrate on their particular
specialties without having to implement every component of
every application.
 Universal Data Access
 Central location for data

12/24/2019
Reusability
6

 Building-block approach
 Central to the OOP concept.
 Improves performance
 More reliable programs
 Avoids reinventing the wheel…

12/24/2019
.Net Framework
7

 Manages and executes applications and Web


services
 Contains a class library
 Framework Class Library or FCL
 Enforces security
 Visual programming
 Microsoft .Net Framework Link

12/24/2019
.Net Framework Layers
8

VB C++ C# JScript

Common Language Specification

ASP.NET Windows Forms

Data and XML

Base Class Library

Common Language Runtime

Windows COM+ Services

12/24/2019
Common Language Infrastructure (CLI)
9

 Contains info about storage of


 data types
 Data that have predefined characteristics
 Ex. Dates, percentages or currency amounts

 Objects
 Has been standardized
 Making it easier to create the .NET Framework for other
platforms.

12/24/2019
Common Language Runtime (CLR)
10

 Executes Visual Basic .Net programs


 Programs are compiled into machine-specific instructions
using two steps:
 Program is compiled into Microsoft Intermediate Language
(MSIL).
 Defines instructions for the CLR

 Then another compiler in the CLR, called the JIT compiler (just-
in-time compiler) translates the MSIL into machine code, for the
particular platform, creating a single application

12/24/2019
Why two compilations?
11

 Provides
 Portability between operating systems

 Interoperability between languages

 Execution-management features
 Memory management
 Security

12/24/2019
Platform Independence
12

 .Net framework provides the ability of a program


to run (without any modification) across
multiple platforms.
 The .NET Framework is actually a set of classes called
base classes.
 Saves Time and Money!
 Don’t reinvent the same code for multiple platforms

 Targets wider audience


 Avoids the expensive process of porting
(converting software from one platform to another)

12/24/2019
Language Interoperability
13

 Programs from different languages are all


compiled into MSIL
 The different parts are combined to create one
program
 MSIL allows the .NET Framework to be language
independent or .Net compliant
 .Net programs are not tied to any particular programming
language.

12/24/2019
Benefits of Language Interoperability in
.Net?
14

 VB.Net, C#, Visual C++.Net programmers can all


work on same project
 Old and new components can work together
 Permits code reusability (code doesn’t have to be
rewritten)
 CLR’s execution-management features
 Code loading and execution
 Application isolation
 Memory management
 Security

12/24/2019
15

 Exception handling
 Interoperability
 Managing security, memory and other features, relieving
programmer of these responsibilities
 Provides huge library of classes providing
reusability
 Framework Class Library (FCL)

12/24/2019
Software Engineering Observation
16

 Reuse of existing classes when building new


classes and programs saves
 time, money & effort
 Reuse also helps in building more reliable and
effective systems
 Why?
 Because existing classes and components go through extensive
testing, debugging and performance tuning.

12/24/2019
Views of VB Between
Vista vs Windows 7 & 8
17

Vista Windows 7 Windows 8


12/24/2019
18

Introduction to
Programming Development

12/24/2019
People Involved in Program Development
19

 Programmer
 Person who solves the problem and writes the instructions for
the computer
 Client
 The person/organization who is responsible for
requesting/purchasing the program
 User
 Any person who uses the program

12/24/2019
Designing Your Program
20

 Critically important to design before beginning to


code
 Coding first is like putting the cart before the horse.
 Doesn’t matter the size of the program -- design first!

12/24/2019
Program Planning Steps
21

1. Analyze – define the problem


2. Design – plan the solution to the problem
3. Design the Interface – select the objects that will be used

4. Code – translate the algorithm into a programming


language
5. Debug & Test – locate and remove any errors in the
program
6. Complete the documentation – Internal & External

12/24/2019
Key Steps to Creating a Visual Program
22

How it should work


Plan the tasks

Design user interface How it should look

Repeat Steps 1 & 2


Write the code

Debug and Test Prepare test criteria

Document & Distribute Put program into use

12/24/2019
Design Process Results
23

 Even for a small program, the design process should


produce the following results:
 A concise list of tasks to be performed by the program
 Deadlines for components
 Clarification of the dependence of one part of the program on
another
 The criteria for testing the program

12/24/2019
Problem Solving
24

 Developing the solution to a problem


 Algorithm
 a step by step series of instructions to solve a problem

 Example:
 How would you give instructions to someone to find your
house?

12/24/2019
Divide-and-Conquer Method
25

 Used in problem solving


 take a large problem and break it into smaller problems

 Solve the small problems first

12/24/2019
Tools Used in Design
26

 Hierarchy Charts/Structure  Pseudocode


Charts  Uses English-like
 Flowcharts/UML phrases with some
Visual Basic terms to
 Graphically depict the logical
outline the task.
steps to accomplish a task and
indicate how the steps relate to  Control Structures
each other  Sequence

 Decision/Selection

 Repetition/Loops/
Iteration

12/24/2019
Pseudocode Example
27

Program: Determine average grade of a class


Initialize Counter and Sum to 0 Initialization
Do While there are more data
Get the next Grade
Add the Grade to the Sum Processing
Increment the Counter
Loop
Compute Average = Sum / Counter
Display Average Output

12/24/2019
Flowchart Symbols
28

12/24/2019
Flowchart Symbols (continued)
29

12/24/2019
Flowchart
Example 30

12/24/2019
Statement Structures
31

 Sequence
 Execute instructions one after another

 Decision
 Allows us to ask questions and execute different instructions
based on result
 Looping
 a series of instructions are executed repeatedly

12/24/2019
Decision Flow Chart
32

12/24/2019
Looping
33 Flow Chart

12/24/2019
Visual Programming
34 Benefits
 Provides the programmer with the ability to create
graphical user interfaces (GUIs).
 Allows the programmer to write much less code
 Does not require the programmer to be a Windows
expert
 Provides Rapid Application Development (RAD) –
code can be developed faster & cheaper

12/24/2019
Programming Languages-Procedural, Event
Driven and Object Oriented
35

 Procedural—Cobol, 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

12/24/2019
36

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.

12/24/2019
37

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.

12/24/2019
The Object Model
38

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
 Properties equate to Adjectives
 Color or size of a Form
 Methods are like Verbs
 Typical methods include Close, Show and Clear
 Events occur when the user takes action
 User clicks a button, User moves a form

12/24/2019
The Object Model
39

 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

12/24/2019
40
Terminology Definition
Object A thing – like a noun in English. Examples include forms and controls you place on forms such
as buttons, text boxes, and icons.
Property 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.

Event 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.
Class 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.

12/24/2019
Object Model Analogy
41

 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

12/24/2019
Visual Studio .NET
42

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


2008 ,2010,2012,2103 and onword
 Visual Basic
 Visual C++
 Visual C# (C sharp)
 Visual J#
 Visual F#
 .NET 2.0 Framework or more
 Visual Studio .NET Editions
 Standard
 Professional
 Enterprise Developer
 Enterprise Architect
 Express

12/24/2019
System Requirements Express Edition
43

 Supported Operating  Hardware


Systems Requirements:
 Windows 7 SP3 (x32)  1.6 GHz or faster processor
(This package)  1 GB of RAM (1.5 GB if running
 Windows 7 SP1 on a virtual machine)
(x86 and x64)  5 GB of available hard disk
 Windows 8 space
(x86 and x64)  5400 RPM hard drive
 Windows Server 2008 R2  DirectX 9-capable video card
SP1 (x64) running at 1024 x 768 or higher
 Windows Server 2012 (x64) display resolution

12/24/2019
Visual Studio Environment
44

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

12/24/2019
The IDE Initial Screen
45

The Visual Studio


IDE with the
Start Page open,
as it first
appears in
Windows , with
an open project.

12/24/2019
Get Started
46

 New Project
 Opens list of existing projects

 Recent Projects
 Contains information on projects recently created or modified

 Get Started
 Focuses on using the IDE for creating programs and learning
VB.

12/24/2019
New Project Window
47

Window Form

Need to rename to something meaningful!

Change Location

12/24/2019
New Project
48

DO NOT MOVE
Properties Window
Or
Solution Explorer Windows!!!!!

12/24/2019
Visual Studio’s Main Windows
49

 Solution Explorer
 Properties
 Toolbox

12/24/2019
Solution Explorer
50

 Provides access to all of a solution’s files.


 If it’s not shown in the IDE, click the Solution
Explorer icon in the IDE , select View > Other
Windows > Solution Explorer or type <Ctrl> <Alt> L.
 Displays the solution’s contents
 When a new or existing solution is opened.

12/24/2019
Properties
Window 51
 4 Methods to Place
Control on Form
 Double-click
 Drag and Drop
 Click, Point, and Click
 Click, Point, and Drag

12/24/2019
IDE Menus
52

12/24/2019
IDE Menus cont.
53

12/24/2019
Toolbox
54

The pushpin in the upper


right corner is the AutoHide
feature and will “stick” the
Toolbox to visible if you want
it to remain visible during design.

Toolbox window
displaying
controls for the
Common Controls
group.

12/24/2019
Auto Hide
55

 Hides Toolbox when not in use


 Vertical push pin icon indicates auto hide is disabled.
 Click the push pin to make it horizontal and enable
auto hide.

push pin

12/24/2019
Properties Window
56

Selected
control

Settings in
Properties Alphabetical
Order

Description
pane
12/24/2019
Modes
57

 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

12/24/2019
VB Application Files
58

 One Solution File—think of


one solution file equals one project .sln
 Solution User Options File .suo
 Form Files .vb
 Resource File for the Form .resx
 Project Files .vbproj
 Project User Options File .vbproj.user
 Application configuration File .app.config
12/24/2019
Remark Statement
59

 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

12/24/2019
Notation
60

 To reference object's properties and events in code


 Object dot Property
 Form.Text, TextBox.Text
 Object dot Method/Function/Subroutine
 Form.Hide( ), TextBox.Focus( )
 To reference an object's events use an underscore
instead of a dot
 Button_Click, ListBox_TextChanged

12/24/2019
Naming Rules and Conventions
61

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.

12/24/2019
Pascal naming convention
62

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.

12/24/2019
Camel Casing and Hungarian naming
conventions
63

Camel Casing and Hungarian Naming Conventions


Control Type and Example Camel Casing Hungarian Example Hungarian
Camel Casing Naming Control Names Naming Control Names
Suffix Prefix

TextBox NameTextBox, txt txtName, txtMajor


MajorTextBox

Button ShippingButton, btn btnShipping, btnExit,


ExitButton, ResetButton btnReset

Label NameLabel, OutputLabel lbl lblName, lblOutput

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

12/24/2019

S-ar putea să vă placă și