You are on page 1of 53

PREPARED BY:

EN NORZELAN BIN SALEH


ELECTRICAL ENGINEERING DEPARTMENT
SULTAN HAJI AHMAD SHAH POLYTECHNIC
1
Visual Basic is available in 3 editions:
1. Enterprise Edition
allows professionals to create robust distributed applications in
a team setting.
includes all the features of the Professional edition, plus Back
Office tools such as SQL Server, Microsoft Transaction Server,
Internet Information Server, Visual SourceSafe, SNA Server,
and more.
Printed documentation provided with the Enterprise edition
includes the Visual Studio Enterprise Features book plus
Microsoft Developer Network CDs containing full online
documentation.
2. Professional Edition
3. Learning Edition


2
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Visual Basic is available in 3 editions:
1. Enterprise Edition
2. Professional Edition
provides computer professionals with a full-featured set of
tools for developing solutions for others.
includes all the features of the Learning edition, plus
additional ActiveX controls, the Internet Information Server
Application Designer, Integrated Data Tools and Data
Environment, and the Dynamic HTML Page Designer.
Documentation provided with the Professional edition
includes the Visual Studio Professional Features book plus
Microsoft Developer Network CDs containing full online
documentation
3. Learning Edition


3
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Visual Basic is available in 3 editions:
1. Enterprise Edition
2. Professional Edition
3. Learning Edition
allows programmers to easily create powerful applications
for Microsoft Windows and Windows NT

.
includes all intrinsic controls, plus grid, tab, and data-bound
controls.
Documentation provided with this edition includes Learn VB
Now (a multimedia CD-ROM title), plus Microsoft Developer
Network CDs containing full online documentation

4
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Minimum hardware and system requirement to run Visual Basic.
The computer on which you install your Visual Studio edition
should meet the following system requirements:
5
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Event-driven programming.
Visual Basic is an event driven programming language. The
common events are Click, DblClick, Load, MouseMove,
MouseDown, MouseUp, KeyPress, KeyUp, KeyDown,
GotFocus, LostFocus etc.

When the user clicks, presses key or moves the mouse, the
particular block of code of the corresponding event procedure
is executed. Then the program behaves in a certain way. This
is event driven programming. When you fire an event, the code
in the event procedure is executed, and then visual basic does
what the code in the event procedure instructs to do.
6
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Event-driven programming.
For example, in the first sample program, when you click the
Print button, click event is fired. Then the code in the click
event procedure gets executed. The code instructs to print a
text on the label. After that you see a text printed on the label
inside the form.
This is the concept of event driven programming. That
means, the code is not executed from top to bottom but it
works when the corresponding event procedure is invoked.

7
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
8
Structured Programming vs Event-driven Programming.
Structured Programming - applications written in procedural
languages execute by proceeding logically through the program
code, one line at a time. Logic flow can be temporarily transferred to
other parts of the program through the GoTo, GoSub, and Call
statements, directing the program from beginning to end.
Event-driven Programming applications execute only when a
specific event calls a section of code assigned to that event. Events
can be triggered by keyboard input, mouse actions, the operating
system, or code in the application.
Eg. Consider what happens when the user clicks a command
button named Command1 on a form. The mouse click is an event.
When the Click event occurs, Visual Basic executes the code in the
Sub procedure named Command1_Click. When the code has
finished running, Visual Basic waits for the next event.
9
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
Process of visual programme design and development:
1. Planning
Planning is an objective of each and every activity, where we
want to discover things that belong to the project.
An important task in creating a software program is extracting the
requirements or requirements analysis.
Customers typically have an abstract idea of what they want as
an end result, but do not know what software should do.
Skilled and experienced software engineers recognize
incomplete, ambiguous, or even contradictory requirements at
this point.
Frequently demonstrating live code may help reduce the risk that
the requirements are incorrect.

10
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
Process of visual programme design and development:
1. Planning
Once the general requirements are gathered from the client, an
analysis of the scope of the development should be determined
and clearly stated. This is often called a scope document.
Certain functionality may be out of scope of the project as a
function of cost or as a result of unclear requirements at the start
of development. If the development is done externally, this
document can be considered a legal document so that if there
are ever disputes, any ambiguity of what was promised to the
client can be clarified.

11
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
Process of visual programme design and development:
2. Implementation, testing and documenting
Implementation is the part of the process where software
engineers actually program the code for the project.
Software testing is an integral and important phase of the
software development process. This part of the process ensures
that defects are recognized as soon as possible.
Documenting the internal design of software for the purpose of
future maintenance and enhancement is done throughout
development. This may also include the writing of an API, be it
external or internal. The software engineering process chosen by
the developing team will determine how much internal
documentation is necessary. Plan-driven models (e.g., Waterfall)
generally produce more documentation than Agile models.

12
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
Process of visual programme design and development:
3. Deployment and maintenance
Deployment starts after the code is appropriately tested,
approved for release, and sold or otherwise distributed into a
production environment.
This may involve installation, customization (such as by setting
parameters to the customer's values), testing, and possibly an
extended period of evaluation.
Software training and support is important, as software is only
effective if it is used correctly.
Maintaining and enhancing software to cope with newly
discovered faults or requirements can take substantial time and
effort, as missed requirements may force redesign of the
software.

13
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
14
1.2 Visual Basic Environment
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Visual Basic Integrated Development Environment - IDE
1.2 Visual Basic Environment
Visual Basic IDE Elements
Menu Bar
Displays the commands you use to work with Visual Basic.
Besides the standard File, Edit, View, Window, and Help menus,
menus are provided to access functions specific to programming
such as Project, Format, or Debug.
Context Menus
Contain shortcuts to frequently performed actions. To open a
context menu, click the right mouse button on the object you're
using. The specific list of shortcuts available from context menus
depends on the part of the environment where you click the right
mouse button. For example, the context menu displayed when
you right click on the Toolbox lets you display the Components
dialog box, hide the Toolbox, dock or undock the Toolbox, or add
a custom tab to the Toolbox.

15
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
Visual Basic IDE Elements
Toolbars
Provide quick access to commonly used commands in the
programming environment. Click a button on the toolbar once to
carry out the action represented by that button.
By default, the Standard toolbar is displayed when you start VB.
Additional toolbars for editing, form design, and debugging can be
toggled on or off from the Toolbars command on the View menu.
Toolbars can be docked beneath the menu bar or can "float" if you
select the vertical bar on the left edge and drag it away from the
menu bar.
Toolbox
Provides a set of tools that you use at design time to place
controls on a form. In addition to the default toolbox layout, you
can create your own custom layouts by selecting Add Tab from the
context menu and adding controls to the resulting tab.
16
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
17
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Visual Basic IDE Windows
1.2 Visual Basic Environment
Type of windows:
Project Explorer
Properties
Object Browser
Form Designer
Code Editor
Form Layout
Immediate
Locals
Watch
18
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
Type of windows in VB Environment:
Project Explorer Window
Lists the forms and modules in your current project. A project is
the collection of files you use to build an application.
Properties Window
Lists the property settings for the selected form or control. A
property is a characteristic of an object, such as size, caption,
or color.
Object Browser
Lists objects available for use in your project and gives you a
quick way to navigate through your code. You can use the
Object Browser to explore objects in Visual Basic and other
applications, see what methods and properties are available for
those objects, and paste code procedures into your application.
19
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.2 Visual Basic Environment
Form Designer
Serves as a window that you customize to design the interface of
your application. You add controls, graphics, and pictures to a
form to create the look you want. Each form in your application
has its own form designer window.
Code Editor Window
Serves as an editor for entering application code. A separate
code editor window is created for each form or code module in
your application.
Form Layout Window
The Form Layout window allows you to position the forms in your
application using a small graphical representation of the screen.
Immediate, Locals, and Watch Windows
These additional windows are provided for use in debugging your
application. They are only available when you are running your
application within the IDE.

20
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.3 Visual Basic Programming
Files that make up a Visual Basic project:
All projects in VB have a .vbp (project) file and at least one
.frm (form file) file.
Always save .frm files first and then save project files. Use
File|Save or File|Save as commands for this purpose or
click Disk icon on toolbar.
Projects with graphics also have .frx (binary form) files. They
are saved automatically.
Module files have a .bas extension and are pure code files.

21
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.3 Visual Basic Programming
Differences between design time, run time, and break time.
Design time - Prior to compile
Run time - After compile, while program is running
Break time - Pausing the execution of code during the
debugging process

22
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.3 Visual Basic Programming
Visual Basic topics in Help menu.


23
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.3 Visual Basic Programming
Objects
An object represents an instance of a class such as Form,
Control, or Component.
In VB code, you must instantiate an object before you can
apply one of the object's methods or change the value of one
of its properties. Instantiation is the process by which an
instance of a class is created and assigned to an object
variable. An example is shown below:
Dim x As New MyClass()
In this example, the variable x is assigned to refer to a new
instance of the class MyClass.
24
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
25
Objects
1.3 Visual Basic Programming
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.3 Visual Basic Programming
Properties
A property is an attribute of an object that defines one of the object's
characteristics, such as size, color, or screen location, or an aspect of its
behavior, such as whether it is enabled or visible.
To change the characteristics of an object, you change the values of its
corresponding properties.
To set the value of a property, affix the reference to an object with a
period, the property name, an equal sign (=), and the new property
value.
eg. the following codes change the caption of a VB Windows Form by
setting the Text property:
myForm.Text = NEW TEXT
You can't set some properties.
You can retrieve information about an object by returning the value of
one of its properties.
26
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Properties Window
27
1.3 Visual Basic Programming
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.3 Visual Basic Programming
Methods
A method is an action that an object can perform.
Eg. Add is a method of the ComboBox object, because it adds a new
entry to a combo box.
The following example demonstrates the Start method of a Timer
component:
' Instantiates a Timer object.
Dim myTimer As New System.Windows.Forms.Timer()
' Invokes the Start method of myTimer.
MyTimer.Start
28
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Events
An event is an action recognized by an object, such as
clicking the mouse or pressing a key, and for which we can
write code to respond.
Events can occur as a result of a user action or program code,
or they can be triggered by the system. We can also develop
our own custom events to be raised by our objects and
handled by other objects.

29
1.3 Visual Basic Programming
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Events List
30
1.3 Visual Basic Programming
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
VB Programme design
Identify Visual Basic object controls.
Explain the steps to place and size object controls.
Apply the various properties of object controls in application.
Create suitable naming prefixes for the object controls
Use suitable Objects Control
set the properties of Object Controls


31
1.3 Visual Basic Programming
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.3 Visual Basic Programming
Visual Basic object controls:

32
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
33
1.3 Visual Basic Programming
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Programme Design:
1.3 Visual Basic Programming
Output
34
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.4 User Interface Concepts
Criteria to be considered in designing the interface:
Seven presentation attributes are:
Clarity: the information content is conveyed quickly and accurately.
Discriminability: the displayed information can be distinguished
accurately.
Conciseness(SOLID): users are not overloaded with extraneous
information.
Consistency: a unique design, conformity with users expectation.
Detectability: the users attention is directed towards information
required.
Legibility (Kebolehbacaan): information is easy to read.
Comprehensibility (menyeluruh) the meaning is clearly
understandable, unambiguous, interpretable, and recognizable.

35
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Dimensions to structure the user interface:
The input/output dimension (the look)
The dialogue dimension (the feel)
The technical or functional dimension (the access to tools
and services)
The organizational dimension (the communication and co-
operation support)

36
1.4 User Interface Concepts
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.4 User Interface Concepts
Interface types:
Single form interface

37
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.4 User Interface Concepts
Interface types:
Multiple form interfaces



38
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
Programme Coding Using Code Window
Discover the Code Window for that particular object.
Create Event Procedures for the object.
Identify the Event Sequence.


39
1.6 Programme Coding Using Code Window
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.6 Programme Coding Using Code Window
Programme Codes Window
40
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.6 Programme Coding Using Code Window
Output
41
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.7 Menus And Submenus In Application
Define menus and submenus.
Identify the naming convention of menu title.
Create menu with the Menu Editor:
Drop-down
Multi-level
Pop-up menus
Modify menus at run time.
Write code programme for the menu commands.
42
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
Dialog boxes and their usage:
The Common Dialog Box control is perhaps the most
powerful control available because of its capability to
become one of several common dialog boxes you've surely
seen in Windows applications.
When you place a common dialog box on a form, you won't
be able to resize it because the control, like the Timer
control, will not appear on the form at runtime, at least not
right away. Your runtime code will have to display the
common dialog box, and the look of the common dialog box
displayed depends on what your code needs at the time.

43
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
Standard dialog boxes for specifying color and fonts, printing,
opening and saving in application.


44
1. File Open dialog box
for requesting a
filename and location
if we are working with
data file.
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
2. The File Save dialog box is for saving data file to a
directory.



45
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
3. The Color dialog box is used
by the user to pick a color.

46
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
4. The Font dialog box shows font information from the user's
system.



47
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
5. The Print dialog box lets the user select a printer for output.


48
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
6. The Folder Browser dialog box lets the user browse folders on
the computer, delete folder or create new folder.


49
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.8 Dialog Boxes In Application
7. The Help dialog box lets the user request the help needed.
The Help window is linked to a help file that you generate,
either a text file or .html file.
The Common Dialog Box control's Help dialog box can
produce the front-end dialog box your user interacts with
when you learn more about providing help.




50
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.9 Message Box And Input Box
Distinguish between message box and input box functions.
A message box is a dialog box you display to give the user
information.
An input box is a dialog box you display to ask the user
questions.
A message box is typically used to display a short single
sentence message to the user. Program execution
continues after the user acknowledges the message box.
An input box, on the other hand, can be thought of as a
message box with a text box. An input box displays a
prompt to the user and obtains text input from the user.



51
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.9 Message Box And Input Box
Will be covered through Practical Work 1:
Create Message box with different parameters.
Create Input Box.
Create Message Box for the return values.
Create the Input Box for the return input by user.
Create Message Box and Input Box in application.

52
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING
1.10 List Boxes and Combo Boxes
Will be covered through Practical Work 1:
Describe the list boxes and combo boxes.
Identify the various types of list boxes and combo boxes
Identify Data into list boxes and combo boxes.
Explain the following:
List.
ListCount
ListIndex
Use List Boxes and Combo Boxes in application.
Applications during Practical Sessions.
53
UNIT 1: INTRODUCTION TO VISUAL BASIC PROGRAMMING

You might also like