SlideShare a Scribd company logo
June 21, 2017 www.snipe.co.in 1
Prepared by: snipe team
June 21, 2017 2
Microsoft Visual Basic 6.0
1. Introduction To VB
2. Programming in VB
3. The Form Object And Controls
4. Sample Programs
5. Database Connectivity
June 21, 2017 3
Agenda
June 21, 2017 4
Visual Basic (VB) is an ideal programming language for developing sophisticated
professional applications for Microsoft Windows.
It makes use of Graphical User Interface for creating robust and powerful applications.
The Graphical User Interface as the name suggests, uses illustrations for text, which
enable users to interact with an application. This feature makes it easier to comprehend
things in a quicker and easier way
In GUI environment, the number of options open to the user is much greater, allowing
more freedom to the user and developer. Features such as easier comprehension, user-
friendliness, faster application development and many other aspects such as
introduction to ActiveX technology and Internet features make Visual Basic an
interesting tool to work with.
Visual Basic (VB) was developed from the BASIC programming language. In the
1970s, Microsoft started developing ROM-based interpreted BASIC for the early
microprocessor-based computers. In 1982, Microsoft QuickBasic revolutionized Basic
and was legitimized as a serious development language for MS-DOS environment.
Later on, Microsoft Corporation created the enhanced version of BASIC called Visual
Basic for Windows.
Introduction To VB
June 21, 2017 5
Introduction To VB
Important Features of Visual Basic (VB)
• Full set of objects .
• Lots of icons and pictures for to use
• Response to mouse and keyboard actions
• Clipboard and printer access
• Full array of mathematical, string handling, and graphics functions
• Can handle fixed and dynamic variable and control arrays
• Sequential and random access file support
• Useful debugger and error-handling facilities
• Powerful database access tools
• ActiveX support
• Package & Deployment Wizard makes distributing your applications simple
June 21, 2017 6
Introduction To VB
Getting Started with Visual Basic 6.0
You will find Microsoft Visual Basic 6.0 on your Start > Programs menu
"First Choice": New | Existing | Recent
See the different choices under each:
• New
Create a new project allows selection of new project from Templates and
Wizards
• Existing
•Browse for existing VB project files
• Recent
The most recent projects opened in VB6
June 21, 2017 7
Continued..
June 21, 2017 8
Continued…
NEW PROJECT OPTIONS
• Standard EXE
Typically used for standard applications
Loads with the intrinsic VB6 controls in the toolbox
Loads a new project with a single form
•ActiveX EXE or ActiveX DLL
Used to create objects used by (other) applications
No forms included, creates a single Class module
•ActiveX Control
Allows developing your own controls (that can be used on forms I other
applications)
Loads with the intrinsic VB6 controls in the toolbox
Loads a new project with a single form-like UserControl module
•VB Application Wizard
Based on user selections, VB creates a skeleton application ready for entering code
to handle menu and button events, etc.
June 21, 2017 9
Continued…
•Addin
Creates a project that runs as an add-in under the VB6 IDE
•Data Project
Creates a new project that contains a single Form, a DataEnvironment object and a
DataReport object.This project includes a number of references to support Data
Access and Data Binding.It also includes several additional controls in the toolbar
June 21, 2017 10
A standard EXE project consist of the following windows
• Project Window
• Form Layout window
• Properties Window
• Form Designer window
• Immediate window
• Toolbox
Introduction To VB
VB Projects contains the following files
•Form files(.frm)
•Binary Files(.frx)
•Standard Modules(.bas)
•Class Modules(.cls)
•Project File (.vbp)
•ActiveX control file(.ocx)
•Resource file(.res)
June 21, 2017 11June 21, 2017 1111
Title Bar Menu and Toolbar
Examples of custom toolbars
Opens the
different
windows
Run, Pause, Stop
Application debugging
Add project, Add "module", Menu editor
Left, Top Width, Height
Selection Coordinates
Introduction To VB
June 21, 2017 12121212
The VB6 IDE
Introduction To VB
June 21, 2017 13June 21, 2017 131313
Creating an Application
Create a new project. File -> New Project
Introduction To VB
June 21, 2017 14June 21, 2017 141414
Select the required tools from the toolbox and place them
on the design form.
If your toolbox is not visible, select View->Toolbox.
Design Form
Introduction To VB
June 21, 2017 15June 21, 2017 1515
Code Form
Introduction To VB
June 21, 2017 16
Common Events
KeyBoard Events
•Keydown
•Keyup
•keyPress
Programming In VB
Mouse Events
•Click
•DblClick
•MouseDown
•Mouseup
•Mousemove
Visual Basic (VB) is an event-driven programming language. Visual Basic programs
are built around events. Events are various things that can happen in a program. this
will become clearer when studied in contrast to procedural programming. In procedural
languages, an application is written is executed by checking for the program logically
through the program statements, one after another. For a temporary phase, the control
may be transferred to some other point in a program. While in an event driven
application, the program statements are executed only when a particular event calls a
specific part of the code that is assigned to the event.
June 21, 2017 17
Programming in VB
Variables:
Variables are the place holders used to store values during execution of a program
Declaring a variable tells Visual Basic to reserve space in memory. It is not must that
a variable should be declared before using it. Automatically whenever Visual Basic
encounters a new variable, it assigns the default variable type and value. This is called
implicit declaration. Though this type of declaration is easier for the user, to have
more control over the variables, it is advisable to declare them explicitly. The variables
are declared with a Dim statement to name the variable and its type. The As type clause
in the Dim statement allows to define the data type or object type of the variable. This
is called explicit declaration.
Declaring Variables
Examples:
Dim varname as Datatype
Dim age as integer
Dim name as string
Dim percent as double
Dim num1 as variant
June 21, 2017 18
Programming in vb 6.0
Data Types
June 21, 2017 19
Programming In VB
Type Casting
Myval = varType(argument)
June 21, 2017 20
Scope And Life time of Variables
Constants
Syntax:
[Public|Private]Const constantname [As type] = expression
Examples:
Const conPi = 3.14159265358979 Public Const conMaxPlanets As Integer = 9
• System -Defined Constants:
These constants are usually prefixed with vb(lower case)
For example the value of a check box control may be 0 (Unchecked),1 (Checked),
2 (Grayed).
Check1.value=vbUnchecked
Check1.value=vbChecked
Check1.value=vbGrayed
• User Defined Constants
Syntax:
Const contant_name As type=value
Example:
Const PI as type Double=3.14159
Programming In VB
June 21, 2017 21
Procedures in Visual Basic 6
Visual Basic programs can be broken into smaller logical components called
Procedures. Procedures are useful for condensing repeated operations such as the
frequently used calculations, text and control manipulation etc. The benefits of using
procedures in programming are:
•It is easier to debug a program a program with procedures, which breaks a program
into discrete logical limits.
•Procedures used in one program can act as building blocks for other programs with
slight modifications.
A Procedure can be Sub, Function or Property Procedure.
Programming In VB
June 21, 2017 22
Programming In VB
Sub Procedures
A sub procedure can be placed in standard, class and form modules. Each time the
procedure is called, the statements between Sub and End Sub are executed. The syntax
for a sub procedure is as follows:
[Private | Public] [Static] Sub Procedurename [( arglist)]
[ statements]
End Sub
arglist is a list of argument names separated by commas. Each argument acts like a
variable in the procedure. There are two types of Sub Procedures namely general
procedures and event procedures.
Event Procedures
An event procedure is a procedure block that contains the control's actual name, an
underscore(_), and the event name. The following syntax represents the event procedure
for a Form_Load event.
Private Sub Form_Load()
....statement block..
End Sub
Event Procedures acquire the declarations as Private by default.
June 21, 2017 23
General Procedures
A general procedure is declared when several event procedures perform the same
actions. It is a good programming practice to write common statements in a separate
procedure (general procedure) and then call them in the event procedure.
In order to add General procedure:
The Code window is opened for the module to which the procedure is to be added.
The Add Procedure option is chosen from the Tools menu, which opens an Add
Procedure dialog box as shown in the figure given below.
The name of the procedure is typed in the Name textbox
Under Type, Sub is selected to create a Sub procedure, Function to create a Function
procedure or Property to create a Property procedure.
Under Scope, Public is selected to create a procedure that can be invoked outside the
module, or Private to create a procedure that can be invoked only from within the
module.
Programming In VB
June 21, 2017 24
Programming In VB
June 21, 2017 25
Function Procedures
Functions are like sub procedures, except they return a value to the calling procedure.
They are especially useful for taking one or more pieces of data, called arguments and
performing some tasks with them. Then the functions returns a value that indicates the
results of the tasks complete within the function.
The following function procedure calculates the third side or hypotenuse of a right
triangle, where A and B are the other two sides. It takes two arguments A and B (of
data type Double) and finally returns the results.
Function Hypotenuse (A As Double, B As Double) As Double
Hypotenuse = sqr (A^2 + B^2)
End Function
Property Procedures
A property procedure is used to create and manipulate custom properties. It is used to
create read only properties for Forms, Standard modules and Class modules.Visual
Basic provides three kind of property procedures-Property Let procedure that sets the
value of a property, Property Get procedure that returns the value of a property, and
Property Set procedure that sets the references to an object.
Programming In VB
June 21, 2017 26
Operators
Programming In VB
June 21, 2017 27
If...Then selection structure
Programming In VB
June 21, 2017 28
Nested If...Then...Else selection structure
If < condition 1 > Then
statements
Else
If < condition 2 > Then
statements
Else
If < condition 3 > Then
statements
Else
Statements
End If
End If
EndIf
Example:
Assume you have to find the grade using
nested if and display in a text box
If average > 75 Then
txtGrade.Text = "A"
ElseIf average > 65 Then
txtGrade.Text = "B"
ElseIf average > 55 Then
txtGrade.text = "C"
ElseIf average > 45 Then
txtGrade.Text = "S"
Else
txtGrade.Text = "F"
End If
Programming In VB
June 21, 2017 29
Select...Case selection structure
Syntax:
Select Case Index
Case 0
Statements
Case 1
Statements
End Select
Example:
Assume you have to find the grade using
select...case and display in the text box
Dim average as Integer
average = txtAverage.Text
Select Case average
Case 100 To 75
txtGrade.Text ="A"
Case 74 To 65
txtGrade.Text ="B"
Case 64 To 55
txtGrade.Text ="C"
Case 54 To 45
txtGrade.Text ="S"
Case 44 To 0
txtGrade.Text ="F"
Case Else
MsgBox "Invalid average marks"
End Select
Programming In VB
June 21, 2017 30
Do While... Loop Statement
The Do While...Loop is used to execute statements until a certain condition is met. The
following Do Loop counts from 1 to 100.
Dim number As Integer
number = 1
Do While number <= 100
number = number + 1
Loop
While... Wend Statement
A While...Wend statement behaves like the Do While...Loop statement. The following
While...Wend counts from 1 to 100
Dim number As Integer
number = 1
While number <=100
number = number + 1
Wend
Programming In VB
June 21, 2017 31
Do...Loop While Statement
The Do...Loop While statement first executes the statements and then test the condition
after each execution. The following program block illustrates the structure:
Dim number As Long
number = 0
Do
number = number + 1
Loop While number < 201
Do Until...Loop Statement
Programming In VB
June 21, 2017 32
The For...Next Loop
Programming In VB
June 21, 2017 33
An array is a consecutive group of memory locations that all have the same name and
the same type. To refer to a particular location or element in the array, we specify the
array name and the array element position number.
Arrays
There are two types of arrays in Visual Basic namely:
iFixed size array : The size of array always remains the same-size doesn't change during the
program execution.
Dim numbers(5) As Integer
The following statement declares a two-dimensional array 50 by 50 array within a procedure.
Dim AvgMarks ( 50, 50)
It is also possible to define the lower limits for one or both the dimensions as for fixed size
arrays. An example for this is given here.
Dim Marks ( 101 To 200, 1 To 100)
An example for three dimensional-array with defined lower limits is given below.
Dim Details( 101 To 200, 1 To 100, 1 To 100)
Dynamic array : The size of the array can be changed at the run time- size changes during the
program execution.
Programming In VB
June 21, 2017 34
User Defined Data Type
Programming In VB
June 21, 2017 35
A User-Defined data type can be referenced in an application by using the variable
name in the procedure along with the item name in the Type block. Say, for example if
the text property of a TextBox namely text1 is to be assigned the name of the electronic
good, the statement can be written as given below.
Text1.Text = ElectronicGoods.ProdName
If the same is implemented as an array, then the statement becomes
Text1.Text = ElectronicGoods(i).ProdName
User-defined data types can also be passed to procedures to allow many related items
as one argument.
Sub ProdData( ElectronicGoods as ProductDetails)
Text1.Text = ElectronicGoods.ProdName
Text1.Text = ElectronicGoods.Price
End Sub
Programming In VB
June 21, 2017 36
Visual Basic Built-in Functions
Many built-in functions are offered by Visual Basic fall under various categories.
These functions are procedures that return a value. The functions fall into the following
basic categories.
•Date and Time Functions
•Format Function
•String Functions
Programming In VB
June 21, 2017 37
Input Box
Displays a prompt in a dialog box, waits for the user to input text or click a button,
and returns a String containing the contents of the text box.
Syntax :
memory_variable = InputBox (prompt[,title][,default])
memory_variable is a variant data type but typically it is declared as string, which
accept the message input by the users. The arguments are explained as follows:
Prompt - String expression displayed as the message in the dialog box. If prompt
consists of more than one line, you can separate the lines using the vbCrLf constant
Title - String expression displayed in the title bar of the dialog box. If you omit the
title, the application name is displayed in the title bar
default-text - The default text that appears in the input field where users can use it as
his intended input or he may change to the message he wish to key in.
x-position and y-position - the position or the coordinate of the input box.
Programming In VB
June 21, 2017 38
Message Box
Displays a message in a dialog box and wait for the user to click a button, and
returns an integer indicating which button the user clicked.
Syntax :
MsgBox ( Prompt [,icons+buttons ] [,title ] )
memory_variable = MsgBox ( prompt [, icons+ buttons] [,title] )
Prompt : String expressions displayed as the message in the dialog box. If prompt
consist of more than one line, you can separate the lines using the vbrCrLf constant.
Icons + Buttons : Numeric expression that is the sum of values specifying the
number and type of buttons and icon to display.
Title : String expression displayed in the title bar of the dialog box. If you omit title,
the application name is placed in the title bar.
Programming In VB
June 21, 2017 39
Programming In VB
Types and values of MsgBox Buttons
June 21, 2017 40
The Form Object And Controls
A Form is container or a window consisting if all elements or controls that make up the
user interface.
A control is an object that can be drawn on a Form object to enable or enhance user
interaction with an application. Controls have properties that define aspects their
appearance, such as position, size and colour, and aspects of their behavior, such as
their response to the user input. They can respond to events initiated by the user or set
off by the system.
For instance, a code could be written in a CommandButton control's click event
procedure that would load a file or display a result.
In addition to properties and events, methods can also be used to manipulate controls
from code. For instance, the move method can be used with some controls to change
their location and size.
June 21, 2017 41
The Form Object And Controls
Intrinsic Controls
June 21, 2017 42
Designing Menus
Visual Basic provides an easy way to create menus with the modal Menu Editor dialog.
The below dialog is displayed when the Menu Editor is selected in the Tool Menu. The
Menu Editor command is grayed unless the form is visible. And also we can display
the Menu Editor window by right clicking on the Form and selecting Menu Editor.
The Form Object And Controls
June 21, 2017 43
The Multiple Document Interface (MDI) :
MDI form acts as a container for other forms in the application.
To create an MDI application, follow these steps:
•Start a new project and then choose Project >>> Add MDI Form to add the
parent Form.
•Set the Form's caption to MDI Window
•Choose Project >>> Add Form to add a SDI Form.
•Make this Form as child of MDI Form by setting the MDI Child property of
the SDI Form to True. Set the caption property to MDI Child window.
The Form Object And Controls
June 21, 2017 44
The Form Object And Controls
June 21, 2017 45
Sample Programs
Program to add two numbers
Step 1: Design the form using controls
June 21, 2017 46
Sample Programs
Step 2: Open the code window and write the code
June 21, 2017 47
Sample Programs
Step 3:Run the project
June 21, 2017 48
Database Connectivity
A database is a collection of data that is related one to another to support a common
application.
For example Employee details - Name, Address, etc. Each of these collections of data
continue a database.
The database accessing methods are as follows:
1) Jet Engine - Accessing Microsoft Access and Visual Basic databases.
2) ODBC (Open Database Connectivity) - Allow access to the client server databases
on a network.
3) ISAM (Index Sequential Access Method) - Used to access flat databases such as
dBase, FoxPro, ParaDox.
June 21, 2017 49
Database Connectivity
ADO (ActiveX Data Object) data control
• The ADO (ActiveX Data Object) data control is the primary interface between a
Visual Basic application and a database. It can be used without writing any code at all!
Or, it can be a central part of a complex database management system. This icon may
not appear in your Visual Basic toolbox. If it doesn’t, select Project from the main
menu, then click Components. The Components window will appear. Select Microsoft
ADO Data Control, then click OK. The control will be added to your toolbox.
• When a data control is placed on a form, it appears with the assigned caption and four
arrow buttons.
June 21, 2017 50
Database Connectivity
• The data control can be used to perform the following tasks:
1. Connect to a database.
2. Open a specified database table.
3. Create a virtual table based on a database query.
4. Pass database fields to other Visual Basic tools, for display or editing. Such
tools are bound tools (controls), or data aware.
5. Add new records or update a database.
6. Trap any errors that may occur while accessing data.
7. Close the database.
June 21, 2017 51
Database Connectivity
• Data Control Properties:
Align Determines where data control is displayed.
Caption Phrase displayed on the data control.
ConnectionString Contains the information used to establish a connection to a
database.
LockType Indicates the type of locks placed on records during editing
(default setting makes databases read-only).
Recordset A set of records defined by a data control’s ConnectionString
and RecordSource properties. Run-time only.
RecordSource Determines the table (or virtual table) the data control is
attached to.
June 21, 2017 www.snipe.co.in 52
Thank You

More Related Content

PPSX
Chapter 01 Introduction to Visual Basic
DOCX
Visual basic
PPT
Visual basic
PPTX
Chapter 1 — Introduction to Visual Basic 2010 Programming
PPS
Vb.net session 02
PPT
visual basic for the beginner
PPTX
Visual basic 6
Chapter 01 Introduction to Visual Basic
Visual basic
Visual basic
Chapter 1 — Introduction to Visual Basic 2010 Programming
Vb.net session 02
visual basic for the beginner
Visual basic 6

What's hot (20)

PPT
Visual Basic Programming
PPT
VB.Net GUI Unit_01
PPT
Introduction to vb.net
PPT
Chapter 01: Intro to VB2010 Programming
PPTX
Introduction to Visual Basic 6.0 Fundamentals
PPT
Introduction to visual basic programming
PPT
Visual programming lecture
PPT
Visual basic ppt for tutorials computer
PDF
Visual Basic IDE Introduction
PDF
Visual Basic 6.0
PPT
Visual programming
PPT
Vb basics
PPTX
Vb.net ide
PPTX
Introduction to visual basic
PDF
PPT
Visual basic
PPTX
Visusual basic
PPTX
visual basic programming
PPTX
Vp lecture1 ararat
PPT
Vb introduction.
Visual Basic Programming
VB.Net GUI Unit_01
Introduction to vb.net
Chapter 01: Intro to VB2010 Programming
Introduction to Visual Basic 6.0 Fundamentals
Introduction to visual basic programming
Visual programming lecture
Visual basic ppt for tutorials computer
Visual Basic IDE Introduction
Visual Basic 6.0
Visual programming
Vb basics
Vb.net ide
Introduction to visual basic
Visual basic
Visusual basic
visual basic programming
Vp lecture1 ararat
Vb introduction.
Ad

Viewers also liked (10)

PPT
Build tool
PPT
Web services engine
PPT
Ide benchmarking
PPT
Project excursion career_orientation
PPT
PPT
Digital marketing
Build tool
Web services engine
Ide benchmarking
Project excursion career_orientation
Digital marketing
Ad

Similar to Visual basics (20)

PPTX
UNIT - 1 VISUAL BASIC PRESENTATION FOR IT
PPT
visual basic v6 introduction
PDF
Vb 6ch123
PPT
Visual basic 6.0
PPTX
Presentation on visual basic 6 (vb6)
PPTX
Vb6.0 intro
PPTX
Vb ch 3-object-oriented_fundamentals_in_vb.net
PPT
Lec02
PPTX
object oriented fundamentals in vb.net
PPTX
LESSON1-INTRODUCTION-TO-VISUALBASIC-1.pptx
PPT
Intro_to_VB.PPT
PPTX
01 Database Management (re-uploaded)
PDF
Ppt on visual basics
PPT
PDF
Visualbasic tutorial
PDF
Visual basic
PDF
VISUAL PROGRAMMING
DOCX
Vb lecture
PPTX
Chapter 1
UNIT - 1 VISUAL BASIC PRESENTATION FOR IT
visual basic v6 introduction
Vb 6ch123
Visual basic 6.0
Presentation on visual basic 6 (vb6)
Vb6.0 intro
Vb ch 3-object-oriented_fundamentals_in_vb.net
Lec02
object oriented fundamentals in vb.net
LESSON1-INTRODUCTION-TO-VISUALBASIC-1.pptx
Intro_to_VB.PPT
01 Database Management (re-uploaded)
Ppt on visual basics
Visualbasic tutorial
Visual basic
VISUAL PROGRAMMING
Vb lecture
Chapter 1

More from Mallikarjuna G D (20)

PPTX
PPTX
Bootstrap 5 ppt
PPTX
Angular 2.0
PPTX
Spring andspringboot training
PPTX
Hibernate
PPT
Jspprogramming
PPT
Servlet programming
PPT
Servlet programming
PPTX
Mmg logistics edu-final
PPTX
Interview preparation net_asp_csharp
PPTX
Interview preparation devops
PPTX
Interview preparation testing
PPTX
Interview preparation data_science
PPTX
Interview preparation full_stack_java
PPTX
Enterprunership
PPTX
Core java
PPTX
Type script
PPTX
Angularj2.0
PPTX
Git Overview
Bootstrap 5 ppt
Angular 2.0
Spring andspringboot training
Hibernate
Jspprogramming
Servlet programming
Servlet programming
Mmg logistics edu-final
Interview preparation net_asp_csharp
Interview preparation devops
Interview preparation testing
Interview preparation data_science
Interview preparation full_stack_java
Enterprunership
Core java
Type script
Angularj2.0
Git Overview

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Lesson notes of climatology university.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
master seminar digital applications in india
human mycosis Human fungal infections are called human mycosis..pptx
Weekly quiz Compilation Jan -July 25.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A systematic review of self-coping strategies used by university students to ...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Final Presentation General Medicine 03-08-2024.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Lesson notes of climatology university.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial diseases, their pathogenesis and prophylaxis
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
2.FourierTransform-ShortQuestionswithAnswers.pdf
Complications of Minimal Access Surgery at WLH
202450812 BayCHI UCSC-SV 20250812 v17.pptx
master seminar digital applications in india

Visual basics

  • 1. June 21, 2017 www.snipe.co.in 1 Prepared by: snipe team
  • 2. June 21, 2017 2 Microsoft Visual Basic 6.0
  • 3. 1. Introduction To VB 2. Programming in VB 3. The Form Object And Controls 4. Sample Programs 5. Database Connectivity June 21, 2017 3 Agenda
  • 4. June 21, 2017 4 Visual Basic (VB) is an ideal programming language for developing sophisticated professional applications for Microsoft Windows. It makes use of Graphical User Interface for creating robust and powerful applications. The Graphical User Interface as the name suggests, uses illustrations for text, which enable users to interact with an application. This feature makes it easier to comprehend things in a quicker and easier way In GUI environment, the number of options open to the user is much greater, allowing more freedom to the user and developer. Features such as easier comprehension, user- friendliness, faster application development and many other aspects such as introduction to ActiveX technology and Internet features make Visual Basic an interesting tool to work with. Visual Basic (VB) was developed from the BASIC programming language. In the 1970s, Microsoft started developing ROM-based interpreted BASIC for the early microprocessor-based computers. In 1982, Microsoft QuickBasic revolutionized Basic and was legitimized as a serious development language for MS-DOS environment. Later on, Microsoft Corporation created the enhanced version of BASIC called Visual Basic for Windows. Introduction To VB
  • 5. June 21, 2017 5 Introduction To VB Important Features of Visual Basic (VB) • Full set of objects . • Lots of icons and pictures for to use • Response to mouse and keyboard actions • Clipboard and printer access • Full array of mathematical, string handling, and graphics functions • Can handle fixed and dynamic variable and control arrays • Sequential and random access file support • Useful debugger and error-handling facilities • Powerful database access tools • ActiveX support • Package & Deployment Wizard makes distributing your applications simple
  • 6. June 21, 2017 6 Introduction To VB Getting Started with Visual Basic 6.0 You will find Microsoft Visual Basic 6.0 on your Start > Programs menu "First Choice": New | Existing | Recent See the different choices under each: • New Create a new project allows selection of new project from Templates and Wizards • Existing •Browse for existing VB project files • Recent The most recent projects opened in VB6
  • 7. June 21, 2017 7 Continued..
  • 8. June 21, 2017 8 Continued… NEW PROJECT OPTIONS • Standard EXE Typically used for standard applications Loads with the intrinsic VB6 controls in the toolbox Loads a new project with a single form •ActiveX EXE or ActiveX DLL Used to create objects used by (other) applications No forms included, creates a single Class module •ActiveX Control Allows developing your own controls (that can be used on forms I other applications) Loads with the intrinsic VB6 controls in the toolbox Loads a new project with a single form-like UserControl module •VB Application Wizard Based on user selections, VB creates a skeleton application ready for entering code to handle menu and button events, etc.
  • 9. June 21, 2017 9 Continued… •Addin Creates a project that runs as an add-in under the VB6 IDE •Data Project Creates a new project that contains a single Form, a DataEnvironment object and a DataReport object.This project includes a number of references to support Data Access and Data Binding.It also includes several additional controls in the toolbar
  • 10. June 21, 2017 10 A standard EXE project consist of the following windows • Project Window • Form Layout window • Properties Window • Form Designer window • Immediate window • Toolbox Introduction To VB VB Projects contains the following files •Form files(.frm) •Binary Files(.frx) •Standard Modules(.bas) •Class Modules(.cls) •Project File (.vbp) •ActiveX control file(.ocx) •Resource file(.res)
  • 11. June 21, 2017 11June 21, 2017 1111 Title Bar Menu and Toolbar Examples of custom toolbars Opens the different windows Run, Pause, Stop Application debugging Add project, Add "module", Menu editor Left, Top Width, Height Selection Coordinates Introduction To VB
  • 12. June 21, 2017 12121212 The VB6 IDE Introduction To VB
  • 13. June 21, 2017 13June 21, 2017 131313 Creating an Application Create a new project. File -> New Project Introduction To VB
  • 14. June 21, 2017 14June 21, 2017 141414 Select the required tools from the toolbox and place them on the design form. If your toolbox is not visible, select View->Toolbox. Design Form Introduction To VB
  • 15. June 21, 2017 15June 21, 2017 1515 Code Form Introduction To VB
  • 16. June 21, 2017 16 Common Events KeyBoard Events •Keydown •Keyup •keyPress Programming In VB Mouse Events •Click •DblClick •MouseDown •Mouseup •Mousemove Visual Basic (VB) is an event-driven programming language. Visual Basic programs are built around events. Events are various things that can happen in a program. this will become clearer when studied in contrast to procedural programming. In procedural languages, an application is written is executed by checking for the program logically through the program statements, one after another. For a temporary phase, the control may be transferred to some other point in a program. While in an event driven application, the program statements are executed only when a particular event calls a specific part of the code that is assigned to the event.
  • 17. June 21, 2017 17 Programming in VB Variables: Variables are the place holders used to store values during execution of a program Declaring a variable tells Visual Basic to reserve space in memory. It is not must that a variable should be declared before using it. Automatically whenever Visual Basic encounters a new variable, it assigns the default variable type and value. This is called implicit declaration. Though this type of declaration is easier for the user, to have more control over the variables, it is advisable to declare them explicitly. The variables are declared with a Dim statement to name the variable and its type. The As type clause in the Dim statement allows to define the data type or object type of the variable. This is called explicit declaration. Declaring Variables Examples: Dim varname as Datatype Dim age as integer Dim name as string Dim percent as double Dim num1 as variant
  • 18. June 21, 2017 18 Programming in vb 6.0 Data Types
  • 19. June 21, 2017 19 Programming In VB Type Casting Myval = varType(argument)
  • 20. June 21, 2017 20 Scope And Life time of Variables Constants Syntax: [Public|Private]Const constantname [As type] = expression Examples: Const conPi = 3.14159265358979 Public Const conMaxPlanets As Integer = 9 • System -Defined Constants: These constants are usually prefixed with vb(lower case) For example the value of a check box control may be 0 (Unchecked),1 (Checked), 2 (Grayed). Check1.value=vbUnchecked Check1.value=vbChecked Check1.value=vbGrayed • User Defined Constants Syntax: Const contant_name As type=value Example: Const PI as type Double=3.14159 Programming In VB
  • 21. June 21, 2017 21 Procedures in Visual Basic 6 Visual Basic programs can be broken into smaller logical components called Procedures. Procedures are useful for condensing repeated operations such as the frequently used calculations, text and control manipulation etc. The benefits of using procedures in programming are: •It is easier to debug a program a program with procedures, which breaks a program into discrete logical limits. •Procedures used in one program can act as building blocks for other programs with slight modifications. A Procedure can be Sub, Function or Property Procedure. Programming In VB
  • 22. June 21, 2017 22 Programming In VB Sub Procedures A sub procedure can be placed in standard, class and form modules. Each time the procedure is called, the statements between Sub and End Sub are executed. The syntax for a sub procedure is as follows: [Private | Public] [Static] Sub Procedurename [( arglist)] [ statements] End Sub arglist is a list of argument names separated by commas. Each argument acts like a variable in the procedure. There are two types of Sub Procedures namely general procedures and event procedures. Event Procedures An event procedure is a procedure block that contains the control's actual name, an underscore(_), and the event name. The following syntax represents the event procedure for a Form_Load event. Private Sub Form_Load() ....statement block.. End Sub Event Procedures acquire the declarations as Private by default.
  • 23. June 21, 2017 23 General Procedures A general procedure is declared when several event procedures perform the same actions. It is a good programming practice to write common statements in a separate procedure (general procedure) and then call them in the event procedure. In order to add General procedure: The Code window is opened for the module to which the procedure is to be added. The Add Procedure option is chosen from the Tools menu, which opens an Add Procedure dialog box as shown in the figure given below. The name of the procedure is typed in the Name textbox Under Type, Sub is selected to create a Sub procedure, Function to create a Function procedure or Property to create a Property procedure. Under Scope, Public is selected to create a procedure that can be invoked outside the module, or Private to create a procedure that can be invoked only from within the module. Programming In VB
  • 24. June 21, 2017 24 Programming In VB
  • 25. June 21, 2017 25 Function Procedures Functions are like sub procedures, except they return a value to the calling procedure. They are especially useful for taking one or more pieces of data, called arguments and performing some tasks with them. Then the functions returns a value that indicates the results of the tasks complete within the function. The following function procedure calculates the third side or hypotenuse of a right triangle, where A and B are the other two sides. It takes two arguments A and B (of data type Double) and finally returns the results. Function Hypotenuse (A As Double, B As Double) As Double Hypotenuse = sqr (A^2 + B^2) End Function Property Procedures A property procedure is used to create and manipulate custom properties. It is used to create read only properties for Forms, Standard modules and Class modules.Visual Basic provides three kind of property procedures-Property Let procedure that sets the value of a property, Property Get procedure that returns the value of a property, and Property Set procedure that sets the references to an object. Programming In VB
  • 26. June 21, 2017 26 Operators Programming In VB
  • 27. June 21, 2017 27 If...Then selection structure Programming In VB
  • 28. June 21, 2017 28 Nested If...Then...Else selection structure If < condition 1 > Then statements Else If < condition 2 > Then statements Else If < condition 3 > Then statements Else Statements End If End If EndIf Example: Assume you have to find the grade using nested if and display in a text box If average > 75 Then txtGrade.Text = "A" ElseIf average > 65 Then txtGrade.Text = "B" ElseIf average > 55 Then txtGrade.text = "C" ElseIf average > 45 Then txtGrade.Text = "S" Else txtGrade.Text = "F" End If Programming In VB
  • 29. June 21, 2017 29 Select...Case selection structure Syntax: Select Case Index Case 0 Statements Case 1 Statements End Select Example: Assume you have to find the grade using select...case and display in the text box Dim average as Integer average = txtAverage.Text Select Case average Case 100 To 75 txtGrade.Text ="A" Case 74 To 65 txtGrade.Text ="B" Case 64 To 55 txtGrade.Text ="C" Case 54 To 45 txtGrade.Text ="S" Case 44 To 0 txtGrade.Text ="F" Case Else MsgBox "Invalid average marks" End Select Programming In VB
  • 30. June 21, 2017 30 Do While... Loop Statement The Do While...Loop is used to execute statements until a certain condition is met. The following Do Loop counts from 1 to 100. Dim number As Integer number = 1 Do While number <= 100 number = number + 1 Loop While... Wend Statement A While...Wend statement behaves like the Do While...Loop statement. The following While...Wend counts from 1 to 100 Dim number As Integer number = 1 While number <=100 number = number + 1 Wend Programming In VB
  • 31. June 21, 2017 31 Do...Loop While Statement The Do...Loop While statement first executes the statements and then test the condition after each execution. The following program block illustrates the structure: Dim number As Long number = 0 Do number = number + 1 Loop While number < 201 Do Until...Loop Statement Programming In VB
  • 32. June 21, 2017 32 The For...Next Loop Programming In VB
  • 33. June 21, 2017 33 An array is a consecutive group of memory locations that all have the same name and the same type. To refer to a particular location or element in the array, we specify the array name and the array element position number. Arrays There are two types of arrays in Visual Basic namely: iFixed size array : The size of array always remains the same-size doesn't change during the program execution. Dim numbers(5) As Integer The following statement declares a two-dimensional array 50 by 50 array within a procedure. Dim AvgMarks ( 50, 50) It is also possible to define the lower limits for one or both the dimensions as for fixed size arrays. An example for this is given here. Dim Marks ( 101 To 200, 1 To 100) An example for three dimensional-array with defined lower limits is given below. Dim Details( 101 To 200, 1 To 100, 1 To 100) Dynamic array : The size of the array can be changed at the run time- size changes during the program execution. Programming In VB
  • 34. June 21, 2017 34 User Defined Data Type Programming In VB
  • 35. June 21, 2017 35 A User-Defined data type can be referenced in an application by using the variable name in the procedure along with the item name in the Type block. Say, for example if the text property of a TextBox namely text1 is to be assigned the name of the electronic good, the statement can be written as given below. Text1.Text = ElectronicGoods.ProdName If the same is implemented as an array, then the statement becomes Text1.Text = ElectronicGoods(i).ProdName User-defined data types can also be passed to procedures to allow many related items as one argument. Sub ProdData( ElectronicGoods as ProductDetails) Text1.Text = ElectronicGoods.ProdName Text1.Text = ElectronicGoods.Price End Sub Programming In VB
  • 36. June 21, 2017 36 Visual Basic Built-in Functions Many built-in functions are offered by Visual Basic fall under various categories. These functions are procedures that return a value. The functions fall into the following basic categories. •Date and Time Functions •Format Function •String Functions Programming In VB
  • 37. June 21, 2017 37 Input Box Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a String containing the contents of the text box. Syntax : memory_variable = InputBox (prompt[,title][,default]) memory_variable is a variant data type but typically it is declared as string, which accept the message input by the users. The arguments are explained as follows: Prompt - String expression displayed as the message in the dialog box. If prompt consists of more than one line, you can separate the lines using the vbCrLf constant Title - String expression displayed in the title bar of the dialog box. If you omit the title, the application name is displayed in the title bar default-text - The default text that appears in the input field where users can use it as his intended input or he may change to the message he wish to key in. x-position and y-position - the position or the coordinate of the input box. Programming In VB
  • 38. June 21, 2017 38 Message Box Displays a message in a dialog box and wait for the user to click a button, and returns an integer indicating which button the user clicked. Syntax : MsgBox ( Prompt [,icons+buttons ] [,title ] ) memory_variable = MsgBox ( prompt [, icons+ buttons] [,title] ) Prompt : String expressions displayed as the message in the dialog box. If prompt consist of more than one line, you can separate the lines using the vbrCrLf constant. Icons + Buttons : Numeric expression that is the sum of values specifying the number and type of buttons and icon to display. Title : String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar. Programming In VB
  • 39. June 21, 2017 39 Programming In VB Types and values of MsgBox Buttons
  • 40. June 21, 2017 40 The Form Object And Controls A Form is container or a window consisting if all elements or controls that make up the user interface. A control is an object that can be drawn on a Form object to enable or enhance user interaction with an application. Controls have properties that define aspects their appearance, such as position, size and colour, and aspects of their behavior, such as their response to the user input. They can respond to events initiated by the user or set off by the system. For instance, a code could be written in a CommandButton control's click event procedure that would load a file or display a result. In addition to properties and events, methods can also be used to manipulate controls from code. For instance, the move method can be used with some controls to change their location and size.
  • 41. June 21, 2017 41 The Form Object And Controls Intrinsic Controls
  • 42. June 21, 2017 42 Designing Menus Visual Basic provides an easy way to create menus with the modal Menu Editor dialog. The below dialog is displayed when the Menu Editor is selected in the Tool Menu. The Menu Editor command is grayed unless the form is visible. And also we can display the Menu Editor window by right clicking on the Form and selecting Menu Editor. The Form Object And Controls
  • 43. June 21, 2017 43 The Multiple Document Interface (MDI) : MDI form acts as a container for other forms in the application. To create an MDI application, follow these steps: •Start a new project and then choose Project >>> Add MDI Form to add the parent Form. •Set the Form's caption to MDI Window •Choose Project >>> Add Form to add a SDI Form. •Make this Form as child of MDI Form by setting the MDI Child property of the SDI Form to True. Set the caption property to MDI Child window. The Form Object And Controls
  • 44. June 21, 2017 44 The Form Object And Controls
  • 45. June 21, 2017 45 Sample Programs Program to add two numbers Step 1: Design the form using controls
  • 46. June 21, 2017 46 Sample Programs Step 2: Open the code window and write the code
  • 47. June 21, 2017 47 Sample Programs Step 3:Run the project
  • 48. June 21, 2017 48 Database Connectivity A database is a collection of data that is related one to another to support a common application. For example Employee details - Name, Address, etc. Each of these collections of data continue a database. The database accessing methods are as follows: 1) Jet Engine - Accessing Microsoft Access and Visual Basic databases. 2) ODBC (Open Database Connectivity) - Allow access to the client server databases on a network. 3) ISAM (Index Sequential Access Method) - Used to access flat databases such as dBase, FoxPro, ParaDox.
  • 49. June 21, 2017 49 Database Connectivity ADO (ActiveX Data Object) data control • The ADO (ActiveX Data Object) data control is the primary interface between a Visual Basic application and a database. It can be used without writing any code at all! Or, it can be a central part of a complex database management system. This icon may not appear in your Visual Basic toolbox. If it doesn’t, select Project from the main menu, then click Components. The Components window will appear. Select Microsoft ADO Data Control, then click OK. The control will be added to your toolbox. • When a data control is placed on a form, it appears with the assigned caption and four arrow buttons.
  • 50. June 21, 2017 50 Database Connectivity • The data control can be used to perform the following tasks: 1. Connect to a database. 2. Open a specified database table. 3. Create a virtual table based on a database query. 4. Pass database fields to other Visual Basic tools, for display or editing. Such tools are bound tools (controls), or data aware. 5. Add new records or update a database. 6. Trap any errors that may occur while accessing data. 7. Close the database.
  • 51. June 21, 2017 51 Database Connectivity • Data Control Properties: Align Determines where data control is displayed. Caption Phrase displayed on the data control. ConnectionString Contains the information used to establish a connection to a database. LockType Indicates the type of locks placed on records during editing (default setting makes databases read-only). Recordset A set of records defined by a data control’s ConnectionString and RecordSource properties. Run-time only. RecordSource Determines the table (or virtual table) the data control is attached to.
  • 52. June 21, 2017 www.snipe.co.in 52 Thank You