0% found this document useful (0 votes)
61 views

Introduction To Visual Basic

This document provides an introduction to Visual Basic, including its history and environment. It discusses how Visual Basic evolved from earlier programming languages like BASIC and its use of an event-driven, visual interface. It also covers Visual Basic fundamentals like variables, data types, operators, and expressions for building programs.
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)
61 views

Introduction To Visual Basic

This document provides an introduction to Visual Basic, including its history and environment. It discusses how Visual Basic evolved from earlier programming languages like BASIC and its use of an event-driven, visual interface. It also covers Visual Basic fundamentals like variables, data types, operators, and expressions for building programs.
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/ 42

Introduction to Visual Basic

Dr. A. Malathi M.Sc.,M.Phil.,Ph.D.,M.Sc(Psych)


Assistant Professor
PG and Research Department of Computer Science
Government Arts College
Coimbatore - 641018
UNIT I
• Introduction - VB Environment – VB
Fundamental: Constants, Variables, Data
Types, Data Declaration – Operators –
Expressions – Library Functions.

Dr. A. Malathi Govt Arts College, Coimbatore 2


History of Programming Languages

• Machine language
• Procedure-oriented languages
• Object-oriented languages
• Event-driven languages
• Natural languages

Dr. A. Malathi Govt Arts College, Coimbatore 3


History of Programming Languages

• Machine Language
– different for each computer processor
• Procedure-Oriented Languages
– BASIC
– FORTRAN
– COBOL
– Pascal
– C
– C++
– JAVA
– Ada

Dr. A. Malathi Govt Arts College, Coimbatore 4


History of Programming Languages

• Object-oriented languages
– Smalltalk
– C++
– Java
– Ada 95
• Event-driven languages
– Visual Basic
– most Visual languages

Dr. A. Malathi Govt Arts College, Coimbatore 5


History of Programming Languages

• Natural languages
– computer will accept a user’s native or natural
language, such as English
– AI, ML, DL
– Researchers continue to work in this area

Dr. A. Malathi Govt Arts College, Coimbatore 6


Background of Visual Basic
• BASIC
– Beginner’s All-purpose Symbolic Instruction Code
– By John Kemeny and Thomas Kurtz
– Designed to teach programming to beginners
– BASIC language interpreter, one of Microsoft’s first
products

Dr. A. Malathi Govt Arts College, Coimbatore 7


Background of Visual Basic
• BASIC
– Included with DOS
– QBASIC - included with DOS Version 5 - subset of BASIC
• Visual Basic
– 1992 - Visual Basic 1 for Windows 3
– Visual Basic 4 - for Windows 95
– Visual Basic 5 - for Office 97
– Visual Basic 6 - for Windows 98 & Office 2000

Dr. A. Malathi Govt Arts College, Coimbatore 8


Visual Basic Editions
• Learning Edition
• Professional Edition
• Enterprise Edition
• Included in Visual Studio suite (analogy Office
for programmers)

Dr. A. Malathi Govt Arts College, Coimbatore 9


Introduction to Visual Basic

Hands-On Exercise 1
– Start Microsoft Visual Basic 6.0
– Open the Welcome Project
– Open the Welcome Form
– Run the Welcome Project
– End the Welcome Project
– Exit Visual Basic

Dr. A. Malathi Govt Arts College, Coimbatore 10


VB Environment

Dr. A. Malathi Govt Arts College, Coimbatore 11


Dr. A. Malathi Govt Arts College, Coimbatore 12
Dr. A. Malathi Govt Arts College, Coimbatore 13
Dr. A. Malathi Govt Arts College, Coimbatore 14
Visual Basic 6 Interactive Development Environment

Project
Toolbox Explorer

Form
Designer
Window

Properties
window

Code Editor
Window

Form Layout
Window
Dr. A. Malathi Govt Arts College, Coimbatore 15
MSDN Library

Navigation Topic Pane


Pane

Dr. A. Malathi Govt Arts College, Coimbatore 16


MSDN Library

• Visual Basic Documentation


– Documentation Map
– What’s New
– Programmer’s Guide
– Samples
– Reference Guidebooks
– Component Tools Guide
– Data Access Guide

Dr. A. Malathi Govt Arts College, Coimbatore 17


VB Fundamentals
• Constant
• Variable
• Data Types
• Declaration

Dr. A. Malathi Govt Arts College, Coimbatore 18


Variables and Constants
Variable
– Memory locations that hold data that can be
changed during project execution
– Example: customer’s name
• Named Constant
– Memory locations that hold data that cannot be
changed during project execution
– Example: sales tax rate

Dr. A. Malathi Govt Arts College, Coimbatore 19


Variables and Constants

• In Visual Basic when you declare a Variable


or Named Constant
– An area of memory is reserved
– A name is assigned called an Identifier
– Follow rules and naming conventions

Dr. A. Malathi Govt Arts College, Coimbatore 20


Data Types

• Boolean • Short (-32,768 to 32,767)


• Byte (0 to 255) • Integer (-2,147,483,648 to
• Char 2,147,483,647)
• Date • Long (larger whole numbers)
• String • Single (floating point accuracy to 6
• Decimal digits)
• Object • Double (floating point accuracy to 14
digits)

Dr. A. Malathi Govt Arts College, Coimbatore 21


Data Types – Memory Usage
• Boolean – 2 bytes • Short – 2 bytes
• Byte – 1 byte • Integer – 4 bytes
• Char – 2 bytes • Long – 8 bytes
• Date – 8 bytes • Single – 4 bytes
• String – varies • Double – 8 bytes
• Decimal – 16 bytes
• Object – 4 bytes

Dr. A. Malathi Govt Arts College, Coimbatore 22


Default Values for Data Types
Data type Default (Initial) value
All numeric types Zero (0)
Boolean False
Char Binary 0
String or Object Empty
Date 12:00 a.m. on January 1, 0001

Dr. A. Malathi Govt Arts College, Coimbatore 23


Declaring Variables

• Declared inside a procedure using a Dim


statement
• Declared outside a procedure using Public,
Private or Dim statements
• Always declare the variable’s data type
• May declare several variables with one
statement
• Use IntelliSense to assist in writing statements
Dr. A. Malathi Govt Arts College, Coimbatore 24
Data Declaration
• The Dim statement is used to associate variables
with specific data types.
• The Dim statement is written as
Dim variable name 1 As data type 1, variable name
2 As data type 2, etc.
Examples:
Dim Counter As Integer
Dim Area As Single
Dim StudentName As String
Dim StudentName As String * 30
Dr. A. Malathi Govt Arts College, Coimbatore 25
Named Constant
• It is also possible to define named constants in
Visual Basic.
• variables can be reassigned different values
within a program, whereas named constants
remain unchanged throughout a program.
• The Const statement is used to declare a named
constant.
• This statement has the general form
• Const constant name As data type = value
• Const TaxRate As Single = 0.28

Dr. A. Malathi Govt Arts College, Coimbatore 26


Suffixes
Suffix Data Type
% integer & long integer
! Single
# double
$ string
Variable Data Type
Index% integer Counter& long integer
TaxRate! single
Ratio# double
CustomerName$ string

Dr. A. Malathi Govt Arts College, Coimbatore 27


Declaration Examples

Dim customerNameString As String


Private totalSoldInteger As Integer
Dim temperatureSingle As Single
Dim priceDecimal As Decimal
Private priceDecimal As Decimal

Dr. A. Malathi Govt Arts College, Coimbatore 28


Conversion Methods

Method Convert To
Integer.Parse Integer
Decimal.Parse Decimal
.ToString String

Govt Arts College, Coimbatore


OPERATORS AND EXPRESSIONS
• Special symbols, called arithmetic operators,
are used to indicate arithmetic operations such
as addition, subtraction, multiplication, division
and exponentiation.
• These operators are used to connect numeric
constants and numeric variables, thus forming
arithmetic expressions

3- 30 Govt Arts College, Coimbatore


Arithmetic Operations

Operator Operation
+ Addition
– Subtraction
* Multiplication
/ Division
\ Integer Division
Mod Modulus – Remainder of division
^ Exponentiation

Dr. A. Malathi Govt Arts College, Coimbatore 31


Hierarchy of Operations

• Order of precedence in arithmetic expressions


from highest to lowest
1. Any operation inside parentheses
2. Exponentiation
3. Multiplication and division
4. Integer division
5. Modulus
6. Addition and subtraction

Dr. A. Malathi Govt Arts College, Coimbatore 32


INSERTING PARENTHESES

• Note the use of parentheses to control


order of precedence

3+4*2 = 11 Multiply then add


(3+4)*2 = 14 Parentheses control: add then multiply
8/4*2 = 4 Same level, left to right: divide then multiply

Dr. A. Malathi Govt Arts College, Coimbatore 33


Using Calculations in Code
• Perform calculations in assignment statements
• What appears on right side of assignment
operator is assigned to item on left side
• Assignment operators
=, +=, -=, *=, /=, \=, &=

Dr. A. Malathi Govt Arts College, Coimbatore 34


Displaying Messages in Message Boxes
• Use Show method of MessageBox to display
message box, a special type of window
• Arguments of Show method
– Message to display
– Optional Title Bar Caption
– Optional Button(s)
– Optional Icon

Dr. A. Malathi Govt Arts College, Coimbatore 35


String Expressions
• Numerical operations cannot be performed on string
constants or string variables.
• strings and string variables can be concatenated (i.e.,
combined, one behind the other).
• In Visual Basic we use either the ampersand (&) or
the plus sign (+) as a string concatenation operator.
• Str1 = "TEN“
• Str2 = "THOUSAND"
• Then the string expression
• Str1 & " " & str2 & " DOLLARS"
Dr. A. Malathi Govt Arts College, Coimbatore 36
ASSIGNING VALUES TO VARIABLES
• The equal sign (=) is used to assign a numeric
or string value to a variable. The general form
is
• Variable = Expression
• X = 12.5
• Cmax = X
• Area = 3.141593 * Radius ^ 2
• Label = "Name: "
Dr. A. Malathi Govt Arts College, Coimbatore 37
DISPLAYING OUTPUT – THE Print
STATEMENT
• The Print statement is used to display information within the
currently active form, beginning in the upper left corner.
• it is very convenient for displaying the results of very simple
programs, and it provides a way to view the results of small
program segments during the development of a large project.
• The Print statement consists of the keyword Print, followed
by a list of output items.
• The output items can be numeric constants, string constants,
or expressions.
• Each new Print statement will begin a new line of output. An
empty Print statement will result in a blank
• Print "Name:", Student, X, (C1 + C2) / 2
Dr. A. Malathi Govt Arts College, Coimbatore 38
Library Function
• Visual Basic contains numerous library functions that provide a quick and
easy way to carry out many mathematical operations, manipulate strings,
and perform various logical operations.
• These library functions are prewritten routines that are included as an
integral part of the language.
• They may be used in place of variables within an expression or a
statement.
• presents several commonly used library functions.
• A library function is accessed simply by stating its name, followed by
whatever information must be supplied to the function, enclosed in
parentheses.
• A numeric quantity or string that is passed to a function in this manner is
called an argument.
• Once the library function has been accessed, the desired operation will be
carried out automatically.
• The function will then return
Dr. A. Malathi
the desired value
Govt Arts College, Coimbatore 39
Examples
• Abs()
• Cos()
• Len()
• Rnd()
• Str()
• Sqt()

Dr. A. Malathi Govt Arts College, Coimbatore 40


References
• SCHAUM'S OUTLINE OF THEORY AND PROBLEMS OF
PROGRAMMING WITH VISUAL BASIC
• http://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/c
odeexamples.html

Dr. A. Malathi Govt Arts College, Coimbatore 41


The End

Dr. A. Malathi Govt Arts College, Coimbatore 42

You might also like