VISUAL BASIC : VISUAL BASIC Introduction About Visual Basic
Presented by R.SHANTHIVICTORIA : Presented by R.SHANTHIVICTORIA
INTRODUCTION : INTRODUCTION What is Visual Basic?
Event Driven Programming Language
Responds to user actions
Interpretative
Programs run as you write them
Object Oriented (somewhat)
Objects know how to react
Emphasis on the Graphical User-Interface (GUI)
Graphic User Interface : Graphic User Interface Graphic User Interface (GUI) comprises
Forms
Controls
Event-driven programming
Object-Oriented & Event-Driven Concepts : Object-Oriented & Event-Driven Concepts Object-Oriented Programming (OOP)
Objects (nouns) controls
Properties (adjectives) form1.Caption
Methods (verbs) debug.print
Event-Driven Programming
User can press keys and click on various buttons and boxes in a window.
Versions of Visual Basic : Versions of Visual Basic Learning Edition
Professional Edition
Enterprise Edition
Visual Basic Projects : Visual Basic Projects Visual Basic projects create several files
Project file: .VBP
Holds the names of other files in the project
Form files: .FRM
Each form is saved as a separate file
Form file contains a description of a form's objects and the Basic code attached to a form
Standard code module: .BAS (optional)
Custom controls: .OCX (optional)
If you include controls that are not part of the standard control set.
Form information: .VBW
The Visual Basic Environment : The Visual Basic Environment Form, Project Explorer, Properties, and Form Layout Windows
Toolbox
Toolbar, Form location & size information
Slide 9 :
The Toolbox : The Toolbox Toolbox contents vary based on which version of Visual Basic you are running.
Toolbox contains a standard set of controls to place on a form.
The Visual Basic Toolbar : The Visual Basic Toolbar The buttons on the toolbar are shortcuts
Toolbar buttons are a quick way to activate frequently used commands
Each button stands for a command that you can also select a the Visual Basic menu
FEATURES OF VB : FEATURES OF VB DATA ACCESS
OLE
USER CONTROLS
VERSION INDEPENDENT
Slide 13 : DATA ACCESS
It allows the user to manage the data from database systems like (MS Access,Oracle,etc.)Keeping visual basic as front end.
OLE(OBJECT Linking Embedded)
It allow the user to use the functionality provided by other applications like Flash, Adobe Packages, Macro Media, etc., besides Microsoft packages and other windows application.
Features of VB(Continued..) : Features of VB(Continued..) User Controls(Active X)
Provides the easy way to create new controls as per the requirement and can be incorporated for various development in VB
Version Independent
Any finished application in VB Programming Language is a true file that uses a run time file, so that the user can freely distribute to any windows operating machines
Where VB can be used : Where VB can be used To create small utility for yourself.
An applicatioon for department, workgroup,large enterprise-wide system.
To create multimedia applications.
To create Database applications on Client/Server Technology.
DATA TYPES : DATA TYPES Data types-control the internal storage of data in Visual Basic.
How do we associate a type to a variable?
VB does this automatically.
By default, Visual Basic uses the Variant data type.
But programmers can always associate variables to a type explicitly.
:
STRINGS : STRINGS A number or a letter represented with double
Quotation is called as String.
In VB,there are lot of inbuilt string function are available to make the application with more interactivity.
STRINGS FUNCTIONS : STRINGS FUNCTIONS
STRINGS FUNCTIONS(continued) : STRINGS FUNCTIONS(continued)
VARIANT : VARIANT Variant in VB is introduced as a flexible data type that could hold any datatype.
Data of any data type
Used when datatype is unknown.
THE EVOLUTION OF VARIANTS : THE EVOLUTION OF VARIANTS
TYPES : TYPES
CONSTANT : CONSTANT The term constant implies the values remain constant throughout the execution of an application.
CONSTANT-Intrinsic & Named : CONSTANT-Intrinsic & Named Constant that we define for program use are called named constant.
Constant that are built into VB are called Intrinsic Constant.
They use a two character prefix to indicate the source
DAO means Data Access Object
Syntax for declaring a Constant : Syntax for declaring a Constant [Public/Private]Const =
Constant name- Should be a valid name
As Type-Data Type
Expression –It is the numeric or the string value that has to be assigned to the constant.
BENEFITS OF USING A CONSTANT : BENEFITS OF USING A CONSTANT No need to remember a specific constant values throughout the program.
That constant can be used wherever the constant is referred in that program.
Once the value of constant is changed in the declaration section of the program,all reference to change it automatically.
Some of the built-in constants that can be used in string variables. : Some of the built-in constants that can be used in string variables.
Some of the built in constants for KeyCodes : Some of the built in constants for KeyCodes
Some of the Visual Basic Constants for the button argument : Some of the Visual Basic Constants for the button argument
DATE FUNCTIONS : DATE FUNCTIONS Known as Internal Function
Used to display System Date and System Time.
Slide 32 :
ARRAYS : ARRAYS An array is set of similar items. All items in an array can have same name .
Array allow you to a series of variables of the same name with an index.
In Visual Basic, we refer to each element in an array through an index e.g. name(0), name(1), .., name(n).
syntax: : syntax: Dim As
Examples:
a.�� Dim grade(7) As Integer
b.�� Dim grade(7) As Integer, name(7) As String
Example a. tells the compiler to reserve six elements for array grade of type Integer.� The value 7 tells defines the upper bound of the array. The compiler allocates 7 �cells� of equal memory sizes with indices starting at 0 (the lower bound) until 6.
WHERE WE CAN USE ARRAY : WHERE WE CAN USE ARRAY Referencing , Manipulating ,etc., are made easier by array.
It is a foundation for the Database Technique.
Rules For Indexing : Rules For Indexing Index number should be nonnegative integer.
It should not start with 0.
Any constant names can be used as an index.
Should be given in rounded brackets().
Index number is also called as Subscript.
Types of Arrays : Types of Arrays Single Dimensional array
Multi Dimensional Array
Dynamic Array
Single Dimensional Array : Single Dimensional Array This type of array having only one subscript.
Example:
Dim Var(10) as integer
Description:
Var(10) - it is an array name
10 - it is the index
Integer –is the type of data you are going to store in all the variables of array.
Multi-Dimensional Array : Multi-Dimensional Array This has more than 2 subscripts.
You should write the number of For Loops that match with the number of Subscripts.
Every dimensional index variable should be unique.
DYNAMIC ARRAY : DYNAMIC ARRAY Dynamic arrays are flexible arrays.
Their size can be changed during the course of the program execution.
Dynamic arrays are very useful when you do not know how many elements to store in the array during development (programming) time.
example : example A dynamic array is not given a size when declared.� For example:
Dim student() As String
You can resize the array at runtime through the statement:
ReDim student(8)
ReDim must be written within procedures.� You can ReDim an array many times.� It can also be used to change the index bounds.� The statement
Redim student(3 to 10)
changes the lower and upper bound to 3 and 6, respectively.
NOTE : NOTE When ReDim is used, all the contents of the array are erased.� Numeric arrays are initialized to 0 and Strings to a zero-length String.� If you want to retain the values, use the keyword Preserve as in the following statement:
ReDim Preserve student(8)
CONTROL ARRAYS : CONTROL ARRAYS With control arrays, you can group related controls and refer to each control by an index.
We then refer to the TextBoxes as txtName(0), txtName(1), �, txtName(9).
LOOPING : LOOPING What is Looping?
Looping is a process which comprises of instructions that are executed repeatedly until some condition is satisfied.
Two Types:
Determinant Loop
Non -Determinant Loop
Slide 45 : Determinant Loop:
It is called as finite loop which means there will be a end point for the loop.
Non- Determinant Loop:
It is called as infinite loop which means there will not be a end point for the loop.
Loop structures in VB : Loop structures in VB 1.For-Loop
2.Do….While
3.Do…..Until
FOR-LOOP : FOR-LOOP This type of loop can be called as counter –style loop process.
It executes the statements until it reaches the end value.
Hence this loop structure is Determinant type.
For Loop(Continued…) : For Loop(Continued…) Syntax:
For = To Step
One or more VB statements
Next
For Loop(Continued…) : For Loop(Continued…) Example:
Dim I as Integer
Dim N as Integer
N=0
For I=1 to 100
N=N+10
Next I
Do While (or) Do Until : Do While (or) Do Until The do loop allows to repeat the code while or until a condition is met.
This do loop will continue its process until a given condition is true.
Once the condition is failed the process will not be repeated.
This type of loop structure is non-determinant.
Do while : Do while Syntax:
Do while()
Statements
Loop Example:
C=0
I=1
Do while (I<10)
C=C+I
I=I+1
loop
Do Until : Do Until Syntax
Do until()
Statements
loop Example:
C=0
I=1
Do until (I<10)
C=C+I
I=I+1
loop
THANK YOU : THANK YOU 53