0% found this document useful (0 votes)
32 views11 pages

Unit 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views11 pages

Unit 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

I

UNIT 1 VISUAL BASIC: INTRODUCTION

Structure

1.0 Introduction
1.1 Objectives
1.2 Start and Exit Visual Basic
1.3 Visual Basic Interface
1.4 Debug Window
1.5 Print Command
1.6 Visual Basic Arithmetic Operators
1.7 Summary

1.0 INTRODUCTION

Welcome to the world of another Microsoft product "Visual Basic" - extremely powerful, state-of-
the-art and at the same time easy-to-use computer-programming environment that enables you to
develop Windows applications. This environment includes everything one needs to create, modify,
test and compile the application. With Visual Basic, one can automate everyday tasks, add custom
required features and functions to suit ones need, and create applications which makes ones task
easier. Visual means the way you develop an application's user interface and basic is the type of
programming code that you write. In this chapter, you will learn some basic concepts of this
powerful language.

As a software developer or as a programmer, you are expected to design and develop every
program that works correctly, efficiently and at the same time easy-to-use by any person who may
or may not be well versed with the computer and its capabilities. The application programmes
written in any language must be such that the user of that programme should find it extremely
friendly in the sense that not much effort should be required on the part of the user to understand
and use an application. It is the ability of the user interface that you create that someone sees when
your program is running.
Components Every program has a user interface in one form or the other. A Visual Basic user ~nterfaceconsists
Windows
Programming of forms and objects. A form is nothing but the window that appears on your screen. Every
&visual Basic window base application will have at least one window associated with it, and since Visual Basic is
a Window based application, has a Window (the form). Objects are items that appear in a form,
such as command buttons, scroll bars, and radio buttons. These objects help the user in activating
the desired operation by clicking at one of the buttons.

1.1 OBJECTIVES

After completion of this unit, you will be able to:

Define Visual Basic Interface and Debug Window,

Discuss arithmetic operators in Visual Basic.

1.2 START AND EXIT VISUAL BASIC

Before trying to start the Visual Basic package on your computer, please ensure that the package
has been properly installed and the shortcut for the same has been created. You will be able to see
the name of this software in the sub-menu of the program menu. Although it is possible to start the
package without the help of the shortcut, but it is easier to activate using the shortcut in case you are
a frequent user of this package.

To start Microsoft Visual Basic, click on Options in the Program Manager to open its drop down
menu. Like every other application in Windows, you click your mouse button when the pointer is
pointing at the Visual basic option (as shown in the picture below) Double click the Visual Basic
icon. As the Visual Basic gets loaded, it will show you Microsoft Visual Basic in design mode. The
Window shall show a new project.

Visual Basic displays five windows when you start it i.e.

1. Microsoft Visual Basic Window (which consists of a title bar, menu bar, and the tool bar)

2. The Form window


3. Project window Visual Basic:
Introduction

4. Toolbox

5. The Properties window

In this window, like every other application in Microsoft, you will find that it is similar to other
window base applications and some of the options listed are quite familiar.

Microsoft Visual Basic Window: The Main Window contains the menu bar and the toolbar.

The Form Window: A form is the window that is displayed when the application is executed. This
Window is initially blank. If this is missing then in the project window, click on Form1 to select it,
then click on the View Form button..

The Project Window: The Project Window displays the files associated with the project that is
currently active. If this is missing then choose View, Project to display it.

Property Window: Property Window displays the information about the form. If this is missing
then choose View, Properties to display it.

Toolbox: Toolbox contains number of controls, which one can use in the creation of the forms. If
this is missing then choose View, Toolbox to display it.

Like any other application in Microsoft Window, the procedure followed to close your work safely
is the same. If you click at the "File" option in the Main Window, you will see the picture as shown
below. To exit from Visual Basic, select Exit from the File menu.
Components Of One can also exit Visual Basic by choosing Close from control menu; or activate Microsoft Visual
Windows
Programming Basic Window and press Alt+F4 or double click on window's Control menu box.
& Visual Basic

1.3 VISUAL BASIC INTERFACE

A user interface makes the user to communicate in two ways. Firstly, the user interface makes it
easy for the user to tell the computer what to do next. Secondly, a user interface enables the
computer to display information on the screen the way it should convey some meaning to the user.
You know that a program is defined as a set of instructions given to the computer to make it
perform a specific task. To make the computer to carry out a task, you specify the steps one by one
to the machine in an interactive manner. Programming in Visual Basic comprises of instructions
that tell Visual Basic, what steps you want it to perform. For displaying anything on your window,
Visual Basic gives you some objects. You may modify the properties of objects, already available
on the interface. Moment you change the properties of an object, the object takes care of displaying
you the information on the screen.
There are number of programming languages, viz. C, Basic, Assembly language etc, that you must
have already used or can use to write programs. These languages are like any other language
because each one has its own set of rules of grammar and set of words. Each language has its
strength and weakness. Many programmers write their program in C language because of its power
and flexibility. In comparison Visual Basic, another powerful language, not only encourages you to
write short programs, but also makes you to adopt the modular approach in programming that
makes the programming interesting and easy to develop any application.

1.4 DEBUG WINDOW

It is extremely important to debug your programmes before they can be put to its actual usage. The
Visual Basic provides you an easy way of debugging your programmes. A window using which you
can keep a track of every instruction of your application while you are designing it, is called the
Debug Window. The features of debugging tools in Visual Basic can help you locate, identify and
correct your coding errors. The moment you run your application in Visual Basic, Debug window 1
automatically opens. This window appears behind Forml. If your application is behaving in a I
manner different from its normal operation, and you are not in a position to find what the error is 1
. ~ n dwhere exactly the problem lies, you do not have to get tensed although it is easy to say so.
Debug window shall take care of this and shall help you. You can set up some break points (a kind ViSUs' Basic:
Introduction
of "wait" in your application) in an application while designing it. You can put the break points at
any place in your application programme but generally the breaks are put where you feel the error is
most likely occurring. In break mode, you can examine and make changes in the current values of
variables and properties, make minor code modifications, and specify which statement the
application will run next. While executing the programme i.e. at run time, you can use it to display
data or messages as the programme gets executed. The debug window is a window, which you can
use to write even a single line program. You can type a command and immediately see the result.

To open the debug window follow the procedure given below:

1. Select start option from the Run menu (or use F5 function key as you must have used this key if
you are familiar with LOTUS 1-2-3). It tells the Visual Basic to switch from design mode to run
mode. You can use to actually run your developed programs.

2. Select Break (or Ctrl+Break key pressed together) from the Run menu to bring the debug
window to the front i.e. to make it an active window.

You will see a window as shown in the picture called as the Debug Window.
Componentsof YOUare familiar with the word processor or a text editor. The debug window is somewhat like a
Windows
Programming text editor because characters appear on the monitor screen as you start typing. You can use the
& Visual Basic mouse to select characters and edit them. But the debug window is different from the text editor in
one very important way. When you press "Enter" key, the debug window tries to execute what you
have typed. To make you understand this statement in a more simple way, when you enter a BASIC
command say "Beep", this will emit a beep sound from your computer speaker. This command is
used to draw the attention to it self. Enter this command by typing BEEP and press Enter key. The
cursor moves to the next line as shown in the picture below as your computer makes a sound.

If you type an incorrect command in the debug window and pressed Enter key; like you have typed
BEAP instead of BEEP and pressed Enter key, Visual Basic displays an alert box to give you an
error message, meaning you have done something wrong and you are being asked to check and
correct it.

To close the debug window, follow the procedure given below:

Type "END" in the debug window and press Enter key. You will see the debug window will
disappear from the screen and Visual Basic is now back in design mode.

Visual Basic has three modes that it displays on the Title bar of the Visual basic:

I Microsoft Visual Basic [design]

[design] appears while you are designingfdeveloping an application program

[run] appears while Visual Basic runstexecutes the current program

[break] appears while the program is stopped, which allows you to use the debug window
Visual Basic:
Introduction
1.5 PRINT COMMAND

The Print command in Visual Basic has a very different meaning what you are generally familiar
with. The Print command does not mean to send output to a printer. The Print command sends it to
the screen. Isn't it not surprising that this is still called a Print command?

The "Basic" language was originally developed by two professors, John G. Kemeny and Thoumas
E. Kurtz, at Dartmouth College around 1963-64. At that time people were working with mainframe
computers rather than micro-computers/personal computers. These computers occupied very large
air-conditioned rooms. To communicate with such computers one used a Tele typewriter rather than
a CRT screen. So whenever a program sent an output to the user, it was actually printed on a piece
of paper rather than displayed on a screen. That is why Kemeny and Kurtz chose the same name
Print.

To use Print command, Debug window must be active. When you type Print and Press Enter key,
you will see the result of the command on your monitor as it gets executed:

When you press Enter key, the Print command displays the result in the debug window in the next
line.

Now let us do some calculations with Print command. To see the result of the following equation,
type the equation followed by the PRINT command. As you press the Enter key, the result of the
equation shall be displayed on the next line on your screen. To try an example, type Print
(2*8+5*2+3*7) and press Enter key and just see the result:

PRINT {4*8 + 5*4 + 3 * 7 )

The syntax rules

Beep and End are the simplest commands. They are only one word long. But to communicate
effectively with your computer, you need more words to build longer sentences. For longer
sentences, you need some rules to combine words..For example, in every spoken language one uses
the rules of grammar for that language. For programming languages these rules are called syntax
Components and they describe how to combine various elements to form a command. Any command you write
Windows
Programming must have at least one word, which is called the keyword or the reserved word. Commands can also
& Visual Basic include additional information like equations. These equations are known as arguments. The Print
command has a syntax rule that says the keyword must appear first and then the arguments. The
correct syntax is:

Print 25+70

Print (2*8), 10,3+9

The following is incorrect:

25+70 Print

"25+7OWPrint

You can display several results of several equations using just one Print command. To do this,
ensure a space between each of the arguments while typing.

PRINT 3*8 10 7 + 9
44 10 16 .

You can also put a comma between the two arguments to tell Print command to leave spaces
equivalent to TAB settings after it displays the first result.

1% PRINT 3*8.10.7+9 ml
Visual 7
lntrodr ,pic:
1.6 VISUAL BASIC ARITHMETIC OPERATORS stion

The computer programme at times is required to perform number of arithmetic operations like
additions, subtraction, division, multiplication etc. This language, like most of the other computer
languages, supports all the arithmetic operations. Whenever you want to do some calculations
between two numbers, use these operators.

Visual Basic Arithmetic Operators


Operator Meaning Example Result

1 + Addition 100+5 105


- Subtraction 100-3 97
* Multiplication 100*5 500
1 Division 10013 33.333
\ Integer Division 100\3 33
A Exponentiation 1OA5 100000
Mod Remainder (Modulo) 10 Mod 4 2
You are already familiar with these operators, may be except \, ", and Mod operators v
to you. hich are new

The \ is called the Integer division operator. This operator gives you the result as r
rather than a fraction like (3.345) i.e. it displays only the integer part. whole number

But "/" divide operator will give you result as


Its Of
I Conpone,
The "Mod" operator is called Modulo. This operator gives the remainder of a division
Windowe
pr0giSG1,
-ic
IP

& Visual Bas,

PRINT 10 Hod 4 !id

"A" operator is called Exponentiation operator, which calculates the power of the number
The fied.
speci.

yo the power 5 (105)or 10*10*10*10*10.


This rneanS 10 1

Check Your 1 Progress


start the visual basic software as explained in this unit. Once the Visual Basic is
On your computer, , following operations.
loaded, perfom the
I ~ O W Sof Visual Basic.
1. See all the five wi'
1d0w and then make it active. Now close the
2. Open the Debug wi'
ld and press Enter key to see the result.
j. Type p N ~ ~
100+50 s 'nd Press the enter key. See the result of this command on your screen.
4. Type
5. Type 50+5 PRINT' ant 1 Press the enter key. Now see the result.
6

next position with a gap of 5 spaces.


6. ~ i ~ then 25
and ~ l ~ ~
7. perfom some more opera tiom using other arithmetic operators. In case of any difficulty consult
your notes.
in the file I 'lamed 'SELF". Close the Visual Basic.
g. Save
Visual Basic:
Introduction
1.7 SUMMARY

In this Chapter you have been exposed to the world of Visual Basic, powerful and easy to use
Microsoft programming language. The following features have been explained:

Visual Basic provides an excellent environment for both beginners and professionals to create
efficient applications.

It is powerful and easy-to-use programming language.

It displays five windows - a blank Microsoft Visual Basic main Window, Properties window,
Project window, Toolbox and the Form window.

A window using which one can keep a track of errors while developing an application, it is the
Debug Window.

To see an output on the monitor one can use the Print command.

Arithmetic operators, to do some calculations between two numbers.

You might also like