Chapter 1 - Introduction To VB Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

CHAPTER 1

INTRODUCTION TO VISUAL BASIC


PROGRAMMING

JUNE 20, 2016


INTAN SHAFINAZ ABD. RAZAK
EED, PTSB.
Page |1

1.0 INTRODUCTION TO VISUAL BASIC PROGRAMMING

1.1 Know the Visual Basic Editions, Requirements and Integrated


Development Environment.

1.1.1 Identify the editions of Visual Basic Programming.

Visual Basic 6.0 versus Other Versions of Visual Basic


The original Visual Basic for DOS and Visual Basic For Windows were introduced in 1991.

 Visual Basic 3.0 (a vast improvement over previous versions) was released in 1993.
 Visual Basic 4.0 released in late 1995 (added 32 bit application support).
 Visual Basic 5.0 released in late 1996. New environment, supported creation of
 ActiveX controls, deleted 16 bit application support.

And, now Visual Basic 6.0 - some identified new features of Visual Basic 6.0:
 Faster compiler
 New ActiveX data control object
 Allows database integration with wide variety of applications
 New data report designer
 New Package & Deployment Wizard
 Additional internet capabilities

16 Bits versus 32 Bits

 Applications
Applications built using the Visual Basic 3.0 and the 16 bit version of Visual Basic 4.0 will
run under Windows 3.1, Windows for Workgroups, Windows NT, or Windows 95

Applications built using the 32 bit version of Visual Basic 4.0, Visual Basic 5.0 and Visual
Basic 6.0 will only run with Windows 95 or Windows NT (Version 3.5.1 or higher).

In this class, we will use Visual Basic 6.0 under Windows 95, recognizing such applications
will not operate in 16 bit environments.

1.1.2 Identify Visual Basic system requirements.

System Requirements for Visual Basic Applications

The following hardware and software is required for Visual Basic applications:

 Pentium® 90MHz or higher microprocessor.

 VGA 640x480 or higher-resolution screen supported by Microsoft Windows.

 Microsoft Windows NT 4.0 or later, or Microsoft Windows 95 or later.


Page |2

 24 MB RAM for Windows 95/98, 32 MB for Windows NT.

 Microsoft Internet Explorer version 4.01 or later (version 4.01 Service Pack 1 or later
for DHTML application developers, and 4.x for end-users of these applications).

 Disk space requirements:


 Standard Edition: typical installation 48 MB, full installation 80 MB.

 Professional Edition: typical installation 48 MB, full installation 80 MB.

 Enterprise Edition: typical installation 128 MB, full installation 147 MB.

 Additional components (if required): MSDN (for documentation): 67 MB,


Internet Explorer 4.x: approximately 66 MB.
 CD-ROM (no MS-DOS support assumed).

1.1.3 Describe the Visual Basic Integrated Development


Environment (IDE).

1.1.3 List the elements in IDE.

One of the most significant changes in Visual Basic 6.0 is the Integrated Development
Environment (IDE). IDE is a term commonly used in the programming world to describe the
interface and environment that we use to create our applications. It is called integrated
because we can access virtually all of the development tools that we need from one screen
called an interface. The IDE is also commonly referred to as the design environment, or the
program.

The Visual Basic IDE is made up of a number of components

 Menu Bar
 Tool Bar
 Project Explorer
 Properties window
 Form Layout Window
 Toolbox
 Form Designer
 Object Browser
 Code Window

1.1.4 Identify the properties windows in Visual Basic application.

Six windows appear when you start Visual Basic.

i. The Main Window consists of the title bar, menu bar, and toolbar. The title bar
indicates the project name, the current Visual Basic operating mode, and the
current form. The menu bar has drop-down menus from which you control the
Page |3

operation of the Visual Basic environment. The toolbar has buttons that provide
shortcuts to some of the menu options. The main window also shows the location
of the current form relative to the upper left corner of the screen (measured in
twips) and the width and length of the current form.

ii. The Form Window is central to developing Visual Basic applications. It is where
you draw your application.
Page |4

iii. The Toolbox is the selection menu for controls used in your application.

iv. The Properties Window is used to establish initial property values for objects.
The drop-down box at the top of the window lists all objects in the current form.
Two views are available: Alphabetic and Categorized. Under this box are the
available properties for the currently selected object.

v. The Form Layout Window shows where (upon program execution) your form
will be displayed relative to your monitor’s screen:
Page |5

vi. The Project Window displays a list of all forms and modules making up your
application. You can also obtain a view of the Form or Code windows (window
containing the actual Basic coding) from the Project window.

1.1.6 Define the design time, run time and break time.

Visual Basic has three distinct modes.


 While you are designing the user interface and writing code, you are in design time.
 When you are testing and running project, you are in run time.
 If you get an error or pause project execution, you are in break time.

1.2 Understand the Visual Basic Programming, Editions, Requirements


and Environment.

1.2.1 Explain the term event-driven programming.

Visual Basic is event-driven, meaning code remains idle until called upon to respond to
some event (button pressing, menu selection,). Visual Basic is governed by an event
processor. Nothing happens until an event is detected.

Once an event is detected, the code corresponding to that event (event procedure) is executed.
Program control is then returned to the event processor.
Page |6

1.2.2 Explain the process of visual programme design and development.

Steps in Developing Application

There are three primary steps involved in building a Visual Basic application:
1. Draw the user interface
2. Assign properties to controls
3. Attach code to controls

You must know that the Application (Project) is made up of:


 Forms - Windows that you create for user interface
 Controls - Graphical features drawn on forms to allow user interaction (text boxes,
labels, scroll bars, command buttons, etc.) (Forms and Controls are objects.)
 Properties - Every characteristic of a form or control is specified by a property.
Example properties include names, captions, size, color, position, and contents. Visual
Basic applies default properties. You can change properties at design time or run time.
 Methods - Built-in procedure that can be invoked to impart some action to a
particular object.
 Event Procedures - Code related to some object. This is the code that is executed
when a certain event occurs.
 General Procedures - Code not related to objects. This code must be invoked by the
application.
 Modules - Collection of general procedures, variable declarations, and constant
definitions used by application.

1.2.3 Explain the steps to writing the Visual Basic projects.

This is the example of steps involve in writing simple VB project.

txtBox1

cmdMerah
Page |7

i) Build a form as shown above and rename the textbox to txtBox1 and command
button as cmdMerah.
ii) Double-click on the command button (cmdMerah) and to key-in the procedure in
the space between Private Sub cmdCheck_Click............. End Sub.

Private Sub cmdMerah_Click()

txtBox1.ForeColor = vbRed

End Sub

iii) Run the program and get the output.

Another example
Page |8
Page |9

1.2.4 Explain the various files that make up a Visual Basic project.

Please follow these step to save your Visual Basic project.

1. Put every Visual Basic project into its own separate folder. Create a new folder ( a
new name) for each revision. Make your names meaningful.
2. Most projects start out with a generic name of "Project1." Click on the line in the
Project Window that says Project (Project1) Go down to the properties window, and
rename Project1 to something that is appropriate for that task.
3. Click the Save BUTTON. Do not go to the File menu. Clicking the Save button will
bring up a dialog box titled "Save File As" and will require you to name the form file.
I suggest that you name the form using the same name as the project.
4. Be sure to tell Visual Basic WHERE you want to save the project, in the folder that
you have created for it.
5. When you click Save, your form is saved with the name you gave it, and an extension
".frm"
6. Then, another window opens where you will save the project files. Do so using the
same filename and in the same folder. VB will add the ".vbp" extension.
7. When you want to exit the project, you will be asked if you want to save changes. Say
yes, because at this time VB will make a third file, the .vbw file
8. When working on the hard drive, follow these directions, too. Be sure you know
where your files are, and that you have them all in the same folder. When you want to
transfer it, just copy the whole folder, making sure that all three files are in the folder.
9. Whatever you do, do not just drag files into a folder. The project file "remembers"
where the form file was originally located. The .vbw file has recorded the path to the
P a g e | 10

original forms and folders. Make sure the files are saved into the same folder. You
can do "Save Project As" and "Save Form As" from the File menu to see where they
are, and then cancel the "Save As" if they are OK. If the form file is not in the same
folder as the project file, then use the "Save form As" command to put the form file
into the right place.

The extension file you should get is:

File types

To develop an application, a project is created to manage all the different files that make up
the application. A project can consists of :-
- One project file that keeps track of all the components (.vbp).
- One file for each form (.frm).
- Optionally, one file for each standard module (.bas).
- One binary data file for each form containing data for properties of controls
on the form (.frx). These files are not editable and are automatically
generated for any .frm file that contains binary properties, such as Picture or
Icon.
- Optionally, one file for each class module (.cls).
- Optionally, one or more files containing ActiveX controls (.ocx).
- Optionally, a single resource file (.res).

Now, please get closer.


P a g e | 11

1.2.5 Explain the concepts of objects, properties, and methods.

All the controls in the ToolBox except the Pointer are objects in Visual Basic. These objects
have associated properties, methods and events.

Real world objects are loaded with properties. For example, a flower is loaded certain color,
shape and fragrance. Similarly programming objects are loaded with properties. A property is
a named attribute of a programming object. Properties define the characteristics of an object
P a g e | 12

such as Size, Color etc. or sometimes the way in which it behaves. For example, a TextBox
accepts properties such as Enabled, Font, MultiLine, Text, Visible, Width, etc.

 Enables property allows the TextBox to be enabled or disabled at run time depending
on the condition set to True or False.
 Font property sets a particular font in the TextBox.
 MultiLine property allows the TextBox to accept and display multiple lines at run
time.
 Text property of the TextBox control sets a particular text in the control.
 Visible property is used to hide the object at run time.
 Width property sets the TextBox to the desired width at design time.

The properties that are discussed above are design-time properties that can be set at the
design time by selecting the Properties Window. But certain properties cannot be set at
design time. For example, the CurrentX and CurrentY properties of a Form cannot be set at
the design time.

A method is an action that can be performed on objects. For example, a cat is an object. Its
properties might include long white hair, blue eyes, 3 pounds weight etc. A complete
definition of cat must only encompass on its looks, but should also include a complete
itemization of its activities. Therefore, a cat's methods might be move, jump, play, breath etc.

Similarly in object-oriented programming, a method is a connected or built-in procedure, a


block of code that can be invoked to impart some action on a particular object. A method
requires an object to provide them with a context. For example, the word Move has no
meaning in Visual Basic, but the statement,

Text1.Move 700, 400

Performs a very precise action. The TextBox control has other associated methods such as
Refresh, SetFocus, etc.

The Refresh method enforces a complete repaint of the control or a Form. For example,
Text1.Refresh refreshes the TextBox.

The Setfocus method moves the focus on the control. For Example Text1.SetFocus sets the
focus to TextBox control Text1.

1.2.6 Explain the elements in IDE.

Integrated Development Environment Elements

The Visual Basic integrated development environment (IDE) consists of the following
elements.
P a g e | 13

i. 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.

ii. Toolbars

Provide quick access to commonly used commands in the programming environment. You
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 Visual Basic. 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.

iii. 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.

iv. 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.

v. 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.

vi. Form Layout Window

The Form Layout window allows you to position the forms in your application using a small
graphical representation of the screen.

vii. Toolbox

In the tool box many controls are available like Text Box, Label, Command Button, Check
Box and etc., to create an application.

viii. 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.
P a g e | 14

ix. 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.

x. Code Window

Once we returned to form, double click on the OK button on your form. A new window will
appear, and some VB code will be automatically inserted. This is known as the Code
Window.

1.2.7 Review the Visual Basic topic in Help Menu.

You can use Help menu in Visual Basic Toolbar or just browsing the web to get any
assistance in your problems.

REFERENCES
https://www.uop.edu.jo/download/research/members/vb6_1__1_.0%20-
%20visual%20basic%20-%20learn%20visual%20basic%206.0%20(nice%20manual).pdf
https://msdn.microsoft.com/en-us/library/aa733592(v=vs.60).aspx
P a g e | 15

You might also like