Uploaded by Elangelo M

Chapter 1

advertisement
Programming
Cha pt e r 1:
The Vi sua l Ba si c Envi r onm e nt
Programming Languages
▹ E.g. C++. BASIC, COBOL, Pascal,
Java, C#, Visual Basic
▹ Visual Studio containsObject
Oriented Programming Languages
▹ Create programs where user can
press keys, buttons that access
different functions
2
Objects, Properties and
Me t hods
OBJECTS
3
Properties
Methods
CLASS
▹ Blueprint used to create object
▹ Object becomes a class and class
contains/encapsulates attributes
and behaviours
▹ Instance of a class–create an
object from a class
■ Ferrari Enzo, Ferrari F40 are
instances (examples) of the
Ferrari class
■ Casio Telememo 30, Seiko
Kinetic, FitBit Watch are
instances of a watch class
4
▹ 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
5
MS Visual Studio 2015
▹ IDE–Integrated Development
environment
Contains all tools needed to easily
create applications
▹ You create the user interface
■ How the user sees the
■
system
How the user uses the
system
▹ Remember as developers you
are creating applications that
other people will use
6
The Graphical User Interface
(GUI )
Labels
Text Boxes
Radio
Buttons
Picture Box
CheckBox
Buttons
Drop Down
Box
7
Starting and Configuring
Vi sua l St udi o
8
Starting and Configuring
Vi sua l St udi o
(cont ’d.)
9
Starting and Configuring
Vi sua l St udi o
(cont ’d.)
1
0
Figure 1-3: Options dialog box
Starting and Configuring
Vi sua l St udi o
(cont ’d.)
1
1
Figure 1-4: Microsoft Visual Studio Community 2015 startup
screen
Creating a VB Windows Form 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
12
MS Visual Basic 2015
▹ Starting MS Visual
Studio
▹ Chooseyour
environment
▹ Start a project
New Project dialog box
13
MS Visual Basic 2015 Interface
Files of
solution
Form
ToolBox
Properties
14
Name of file
Title Bar can be changed using
form properties
Windows Form Object
15
▹ All objects placed on form
▹ GUI–Graphical User Interface
▹ Forms have various properties
that could be changed–Project
Designer Window
Creating a VB Windows Form Application
▹ 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
16
VB Views
▹ WindowsForm 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]
17
Properties Window
Various Properties for
each object
▹ Text, Name, Font,
Size, StartPosition
etc.
▹ Description at the
bottom of the
window
Each Property affects
the functioning and
appearance of the
object
▹ For example, the
Text property of the
form displayes the
title of the form
18
Creating a VB Windows Form Application
19
Accessing the Project Properties
Double Click to
access
Various options
could change
20
Properties of a Windows
For m
(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
2
1
Properties of a Windows
For m
(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
2
2
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
2
3
The Toolbox Wi ndow
24
Using the Format Menu
▹ Format menu:
■ provides options for manipulating
■
controls on the form
First control selected is the reference
control
25
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
26
The Code Editor Wi ndow
▹ Class statement
■ Used to define a class
▹ Syntax
■ Rules of the language
27
The first program
Write a program that says Hello
when a button is clicked.
28
Writing VB Programs
▹
1.
2.
3.
3 Step process
Design the user interface
Plan the properties
Plan the basic code
29
The Interface
Text property for
form
Message displayed in
a textbox
Place your screenshot here
30
Buttons to display
message in chosen
language
The code
Each button needs to
be programmed.
When clicked:
▹ The label on the
form changes
using the =
▹ The text within the
textbox changes to
the language using
the =
▹ Remarks in green
start with ‘
Place your screenshot here
31
Some initial coding
st a t e m e nt s
Assignment
▹ Represented using =
Using methods of an
object
▹ Allocates a value to an
object/variable/
control/property
▹ Command the object
to do something
▹ Object.property = value
▹ TextBox1.Hide()
▹ Textbox1.Text =
“Hello”
▹ Me.BackColor =
Color.Red
▹ Object.Method
▹ Me.Close()
Remarks
▹ Comments made by
the programmer in
the code
▹ Shown in green
▹ Tells someone what
the code is going to
do
▹ Compiler of VB
ignores these
statements
32
Finding and Fixing Errors
▹ 3 types –Syntax, Runtime and
Logic
Debugging–Finding and fixing errors
▹ Syntax
■ Breaking VB’s rules
■ VB generally underlines these
errors for you
33
Checking your errors
▹ Run Time
■ Error occurs during execution -
Statements that fail to execute, such
as impossible arithmetic operations
▹ Logical error
■ Program runs properly from start to
■
finish
The answer is wrong/unexpected
34
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
"Look at the Title Bar"
Download