SlideShare a Scribd company logo
1 of 29
Download to read offline
Introduction
to
VP Programming
Prof. K ADISESHA (Ph. D)
Introduction
to
Part-2
Introduction
Data types
Queries
Variables
Operators
2
Visual Basic 6
Prof. K. Adisesha (Ph. D)
Conversion
INTRODUCTION
Prof. K. Adisesha (Ph. D)
3
Programming using Visual Basic:
Visual Basic uses building blocks such as Variables, Data Types, Procedures, Functions
and Control Structures in its programming environment.
This section concentrates on the programming fundamentals of Visual Basic with the
blocks specified.
➢ MODULES : Code in Visual Basic is stored in the form of modules, which are of three
type Form Modules, Standard Modules and Class Modules.
➢ Each module can contain:
❖ Declarations :May include constant, type, variable and DLL procedure declarations
❖ Procedures : A sub function, or property procedure that contain pieces of code that
can be executed as a unit.
DATA TYPES
Prof. K. Adisesha (Ph. D)
4
Data types in Visual Basic:
The compiler sets apart a number of bytes for each of the variable depending on the
data type of holds
Data types in Visual Basic
❖ Numeric
❖ String
❖ Date
❖ Boolean
❖ Variant
Data type Size Range
Byte 1 byte Byte Store integer values in the range of 0 - 255
Integer 2 bytes Integer Store integer values in the range of (-32,768) - (+ 32,767)
Long 4 bytes Long Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468)
Single 4 bytes Single Store floating point value in the range of (-3.4x10-38) - (+ 3.4x1038)
Double 8 bytes Double Store large floating value which exceeding the single data type value
Currency 8 bytes Currency store monetary values. It supports 4 digits to the right of decimal point
and 15 digits to the left
Decimal 14 bytes Decimal stores value with 28 places to the right of the decimal; smallest non-zero
number is +/-0.0000000000000000000000000001
DATA TYPES
Prof. K. Adisesha (Ph. D)
5
➢ Numeric Data type: The fundamental data types in Visual Basic including variant
are integer, long, single, double, string, currency, byte and boolean.
DATA TYPES
Prof. K. Adisesha (Ph. D)
6
Data types :
➢ String: Use to store alphanumeric values. A variable length string can store
approximately 4 billion characters. Uses storage size10 bytes +
➢ Date : Use to store date and time values. A variable declared as date type can store
both date and time values and it can store date values 01/01/0100 up to 12/31/9999. It
uses storage size of 8 bytes
➢ Boolean : Boolean data types hold either a true or false value. These are not stored as
numeric values and cannot be used as such. Values are internally stored as -1 (True)
and 0 (False) and any non-zero value is considered as true. Uses storage size of2 bytes
➢ Variant : In Visual Basic if we declare a variable without any data type by default the
data type is assigned as variant data type.
VARIABLES
Prof. K. Adisesha (Ph. D)
7
Variables:
Variables are the memory locations which are used to store values temporarily. A
defined naming strategy has to be followed while naming a variable.
➢ A variable name must begin with an alphabet letter and should not exceed 255
characters.
➢ It must be unique within the same scope.
➢ The different ways of declaring variables in Visual Basic are listed below:
❖ Explicit Declaration
❖ Implicit Declaration
❖ Using Option Explicit statement
VARIABLES
Prof. K. Adisesha (Ph. D)
8
Variables:
Variables are the memory locations which are used to store values temporarily. A
defined naming strategy has to be followed while naming a variable.
➢ The following are the rules when naming the variables in Visual Basic:
❖ It must be less than 255 characters
❖ No spacing is allowed
❖ It must not begin with a number
❖ Period is not permitted
❖ Cannot use exclamation mark (!), or the characters @, &, $, #
❖ Cannot repeat names within the same level of scope.
VARIABLES
Prof. K. Adisesha (Ph. D)
9
Explicit variables declaration :
Declaring a variable tells Visual Basic to reserve space in memory. to have more
control over the variables, it is advisable to declare them explicitly.
➢ The variable can have different names and different types of values.
➢ The dim is keyword in visual Basic and has language specific meaning.
➢ Syntax for Declaring Variable
Dim VaribaleName As DataType
➢ Example :
Dim Regno as integer
Dim Myname as string
VARIABLES
Prof. K. Adisesha (Ph. D)
10
Implicit variables declaration :
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.
➢ It may be convenient to declare variables implicitly, but it can lead to errors that may
not be recognized at run time
➢ Syntax for Declaring Variable
Dim str1,str2
Str1= “Implicit Declaration”
Str2= Intcount + 1
VARIABLES
Prof. K. Adisesha (Ph. D)
11
Option Explicit variables declaration :
This forces the user to declare all the variables. The Option Explicit statement checks
in the module for usage of any undeclared variables and reports an error to the user.
➢ The user can thus rectify the error on seeing this error message.
➢ The Option Explicit statement can be explicitly placed in the general declaration
section of each module using the following steps.
❖ Click Options item in the Tools menu
❖ Click the Editor tab in the Options dialog box
❖ Check Require Variable Declaration option and
then click the OK button
VARIABLES
Prof. K. Adisesha (Ph. D)
12
Example: Program to find sum and average of two numbers
VARIABLES
Prof. K. Adisesha (Ph. D)
13
Scope of the variable:
The scope of variable determines where you can access that variable in your code.
➢ If a variable is in scope you can read or set its value.
➢ If it is out of scope you will not be able to access it.
➢ Types of scope for variables in visual basic
❖ Global scope: Global variables are in scope anywhere in your application
❖ Module scope :Module level variables are in scope anywhere within the module
where they are declared
❖ Local scope : Local variables are only in scope within the procedure where they
are declared.
Variables
Prof. K. Adisesha (Ph. D)
14
Scope of the variable:
Types of scope for variables in visual basic
➢ Local Variables: A local variable is one that is declared inside a procedure. This
variable is only available to the code inside the procedure.
Dim sum As Integer
➢ Static Variables: Static variables are not reinitialized each time Visual basic invokes a
procedure and therefore retains or preserves value even when a procedure ends.
Static intPermanent As Integer
➢ Module Level Variables: A module level variable is available to all the procedures in
the module. They are declared using the Public or the Private keyword. these
variables are useful for sharing data among procedures in the same module.
Public CustomerName As String
VARIABLES
Prof. K. Adisesha (Ph. D)
15
Local Variables:
A local variable is one that is declared inside a procedure. This variable is only
available to the code inside the procedure and can be declared using the Dim
statements.
Dim sum As Integer
➢ The local variables exist as long as the procedure in which they are declared, is
executing.
➢ Once a procedure is executed, the values of its local variables are lost and the memory
used by these variables is freed and can be reclaimed.
➢ Variables that are declared with keyword Dim exist only as long as the procedure is
being executed.
VARIABLES
Prof. K. Adisesha (Ph. D)
16
Static Variable:
Static variables are not reinitialized each time Visual Invokes a procedure and
therefore retains or preserves value even when a procedure ends. These static variables
are also ideal for making controls alternately visible or invisible.
➢ A static variable is declared as given below.
Static intPermanent As Integer
➢ Variables have a lifetime in addition to scope.
➢ The value of a local variable can be preserved using the Static keyword.
Private Sub Command1_Click ( )
Static Counter As Integer
End Sub
VARIABLES
Prof. K. Adisesha (Ph. D)
17
Module Level Variable:
A module level variable is available to all the procedures in the module. They are
declared using the Public or the Private keyword.
If you declare a variable using a Private or a Dim statement in the declaration section
of a module—a standard BAS module, a form module, a class module, and so on.
➢ A Private module-level variables are visible only from within the module they belong to
and can't be accessed from the outside. these variables are useful for sharing data
among procedures in the same module:
Private LoginTime As Date ' A private module-level variable
➢ A Public module-level variable that can be accessed by all procedures in the module
to share data and that also can be accessed from outside the module.
VARIABLES
Prof. K. Adisesha (Ph. D)
18
Assigning Values to Variables:
After declaring various variables using Dim statements,we can assign values to
variables.
➢ Example:
❖ firstNumber=100
❖ secondNumber=firstNumber-99
❖ userName=“K Adisesha"
❖ userpass.Text = password
❖ Label1.Visible = True
❖ Command1.Visible = false
❖ Label4.Caption = textbox1.Text
❖ ThirdNumber = Val(usernum1.Text)
CONSTANTS
Prof. K. Adisesha (Ph. D)
19
Constants in Visual Basic:
Constant also store values, but as the name implies, those values remains
constant throughout the execution of an application.
➢ Using constants can make your code more readable by providing meaningful names
instead of numbers.
➢ There are a number of built –in constants in Visual Basic.
➢ There are two sources for constants:
❖ System-defined constants : are provided by applications and controls. Visual Basic
constants are listed in the Visual Basic (VB). Form1.WindowState=value
❖ User-defined constants: are declared using the Const statement. It is a space in
memory filled with fixed value that will not be changed.
Const constant_name = value
OPERATORS
Prof. K. Adisesha (Ph. D)
20
Operators in Visual Basic:
An operator is a special symbol which indicates a certain process is carried out.
Operators in programming languages are taken from mathematics.
➢ The operators are used to process data.
➢ Types of operators in Visual Basic:
❖ Arithmetical operators
❖ Relational operators
❖ Logical operators.
OPERATORS
Prof. K. Adisesha (Ph. D)
21
ARITHMETICAL OPERATORS:
Arithmetic operators are used to perform many of the familiar arithmetic operations that
involve the calculation of numeric values represented by literals, variables, other
expressions, function and property calls, and constants.
OPERATORS
Prof. K. Adisesha (Ph. D)
22
RELATIONAL OPERATORS:
Comparison operators are used for Decision Making or compare two expressions and
return a Boolean value that represents the relationship of their values.
➢ It uses If/Then structure
➢ Allows a program to make decision based on the truth or falsity of some expression
Condition:
➢ The expression in an If/Then structure
❖ If the condition is true, the statement in the body of the structure executes
➢ Conditions can be formed by using
❖ Equality operators
❖ Relational operators
OPERATORS
Prof. K. Adisesha (Ph. D)
23
RELATIONAL OPERATORS:
Comparison operators compare two expressions and return a Boolean value that
represents the relationship of their values. There are operators for comparing numeric
values, operators for comparing strings, and operators for comparing objects..
Operators Description Example Result
> Greater than 10>8 True
< Less than 10<8 False
>= Greater than or equal to 10>=8 True
<= Less than or equal to 10<=8 False
== Equal to 10==8 false
<> Not Equal to 10<>8 True
OPERATORS
Prof. K. Adisesha (Ph. D)
24
LOGICAL OPERATORS:
In addition to conditional operators, there are a few logical operators which offer added
power to the VB programs.
➢ Logical operators compare Boolean expressions and return a Boolean result.
➢ Some of these operators can also perform bitwise logical operations on integral
values.
Operators Description
OR OR Operation will be true if either of the operands is true
AND Operation will be true only if both the operands are true
XOR One side or other must be true but not both
NOT Negates true
BUILT IN FUNCTIONS
Prof. K. Adisesha (Ph. D)
25
BUILT IN FUNCTIONS:
Many built in functions are offered by Visual basic under various categories.
➢ These functions return a value.
➢ Types of built in functions in VB are:
❖ Date and Time function
❖ Format function
❖ String function
❖ Numeric function
BUILT IN FUNCTIONS
Prof. K. Adisesha (Ph. D)
26
BUILT IN FUNCTIONS:
Date and Time function: Use to store date and time values. A variable declared as date
type can store both date and time values and it can store date values 01/01/0100 up to
12/31/9999. Time between 0:00:00 and 23:59:59. It uses storage size of 8 bytes
Year Year(now)
Month Month(now)
Day Day(now)
Weekday Weekday(now)
Hour Hour(now)
Minute Minute(now)
Second Second(now)
BUILT IN FUNCTIONS
Prof. K. Adisesha (Ph. D)
27
BUILT IN FUNCTIONS:
Format function & String functions: Use to convert values in other formatted which are
convenient for user to use in application.
CONVERSION
Prof. K. Adisesha (Ph. D)
28
DATA TYPE CONVERSION:
Visual Basic functions either to convert a string into an integer or vice versa and many
more conversion functions.
Conversion To Function Description
Boolean Cbool The function Cbool converts any data type to Boolean 0 or 1
Byte Cbyte The function Cbyte converts any data type to Byte
Currency Ccur The function Ccur converts any data type to currency
Date Cdate The function Cdate converts any data type to date.
Decimals Cdec The function Cdec converts any data type to decimal
Value Cval The CVal function is used to convert string to double-
precision numbers.
Discussion
Prof. K. Adisesha (Ph. D)
29
Queries ?
Prof. K. Adisesha
9449081542

More Related Content

Similar to VB PPT by ADI PART2.pdf

Variable scope ppt in vb6
Variable scope ppt in vb6Variable scope ppt in vb6
Variable scope ppt in vb6AmanHooda4
 
Computer programming - variables constants operators expressions and statements
Computer programming - variables constants operators expressions and statementsComputer programming - variables constants operators expressions and statements
Computer programming - variables constants operators expressions and statementsJohn Paul Espino
 
Pemrograman komputer 3 (representasi data)
Pemrograman komputer  3 (representasi data)Pemrograman komputer  3 (representasi data)
Pemrograman komputer 3 (representasi data)jayamartha
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3Vijay Perepa
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming conceptsandeshjadhav28
 
ASP.Net Technologies Part-2
ASP.Net Technologies Part-2ASP.Net Technologies Part-2
ASP.Net Technologies Part-2Vasudev Sharma
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practicesAnilkumar Patil
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingAbha Damani
 
Introduction to c
Introduction to cIntroduction to c
Introduction to cAjeet Kumar
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAKTabsheer Hasan
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application Raghu nath
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfHouseMusica
 

Similar to VB PPT by ADI PART2.pdf (20)

Variable scope ppt in vb6
Variable scope ppt in vb6Variable scope ppt in vb6
Variable scope ppt in vb6
 
Computer programming - variables constants operators expressions and statements
Computer programming - variables constants operators expressions and statementsComputer programming - variables constants operators expressions and statements
Computer programming - variables constants operators expressions and statements
 
Qtp - Introduction to fundamentals of vbscript
Qtp - Introduction to fundamentals of vbscriptQtp - Introduction to fundamentals of vbscript
Qtp - Introduction to fundamentals of vbscript
 
Pemrograman komputer 3 (representasi data)
Pemrograman komputer  3 (representasi data)Pemrograman komputer  3 (representasi data)
Pemrograman komputer 3 (representasi data)
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
ASP.Net Technologies Part-2
ASP.Net Technologies Part-2ASP.Net Technologies Part-2
ASP.Net Technologies Part-2
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practices
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
C# Dot net unit-3.pdf
C# Dot net unit-3.pdfC# Dot net unit-3.pdf
C# Dot net unit-3.pdf
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAK
 
12.6-12.9.pptx
12.6-12.9.pptx12.6-12.9.pptx
12.6-12.9.pptx
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
 
Storage classes
Storage classesStorage classes
Storage classes
 
Software Engineering CSE/IT.pptx
 Software Engineering CSE/IT.pptx Software Engineering CSE/IT.pptx
Software Engineering CSE/IT.pptx
 
Pc module1
Pc module1Pc module1
Pc module1
 

More from AdiseshaK

Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdfAdiseshaK
 
SP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdfSP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdfAdiseshaK
 
CNS_Solutions-Adi.pdf
CNS_Solutions-Adi.pdfCNS_Solutions-Adi.pdf
CNS_Solutions-Adi.pdfAdiseshaK
 
TOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfTOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfAdiseshaK
 
INPUT OUTPUT MEMORY DEVICE.pdf
INPUT OUTPUT MEMORY DEVICE.pdfINPUT OUTPUT MEMORY DEVICE.pdf
INPUT OUTPUT MEMORY DEVICE.pdfAdiseshaK
 
Macros & Loaders sp.pdf
Macros & Loaders sp.pdfMacros & Loaders sp.pdf
Macros & Loaders sp.pdfAdiseshaK
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdfAdiseshaK
 
Introd to loaders_sp Adi.pdf
Introd to loaders_sp Adi.pdfIntrod to loaders_sp Adi.pdf
Introd to loaders_sp Adi.pdfAdiseshaK
 
Assembler by ADI.pdf
Assembler by ADI.pdfAssembler by ADI.pdf
Assembler by ADI.pdfAdiseshaK
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 
VB PPT by ADI PART4.pdf
VB PPT by ADI PART4.pdfVB PPT by ADI PART4.pdf
VB PPT by ADI PART4.pdfAdiseshaK
 
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdfVB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdfAdiseshaK
 
WP Solutions- Adi.pdf
WP Solutions- Adi.pdfWP Solutions- Adi.pdf
WP Solutions- Adi.pdfAdiseshaK
 
TOC Solutions-Adi.pdf
TOC Solutions-Adi.pdfTOC Solutions-Adi.pdf
TOC Solutions-Adi.pdfAdiseshaK
 
SP Solutions -Adi.pdf
SP Solutions -Adi.pdfSP Solutions -Adi.pdf
SP Solutions -Adi.pdfAdiseshaK
 
CNS Solutions-Adi.pdf
CNS Solutions-Adi.pdfCNS Solutions-Adi.pdf
CNS Solutions-Adi.pdfAdiseshaK
 
VB PPT by ADI part-1.pdf
VB PPT by ADI part-1.pdfVB PPT by ADI part-1.pdf
VB PPT by ADI part-1.pdfAdiseshaK
 
8085 microprocessor notes
8085 microprocessor notes8085 microprocessor notes
8085 microprocessor notesAdiseshaK
 
Introduction to 8085_by_adi_ppt
Introduction to 8085_by_adi_pptIntroduction to 8085_by_adi_ppt
Introduction to 8085_by_adi_pptAdiseshaK
 

More from AdiseshaK (20)

Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
 
SP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdfSP_Solutions_-Adi.pdf
SP_Solutions_-Adi.pdf
 
CNS_Solutions-Adi.pdf
CNS_Solutions-Adi.pdfCNS_Solutions-Adi.pdf
CNS_Solutions-Adi.pdf
 
TOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdfTOC_Solutions-Adi.pdf
TOC_Solutions-Adi.pdf
 
INPUT OUTPUT MEMORY DEVICE.pdf
INPUT OUTPUT MEMORY DEVICE.pdfINPUT OUTPUT MEMORY DEVICE.pdf
INPUT OUTPUT MEMORY DEVICE.pdf
 
AI-ML.pdf
AI-ML.pdfAI-ML.pdf
AI-ML.pdf
 
Macros & Loaders sp.pdf
Macros & Loaders sp.pdfMacros & Loaders sp.pdf
Macros & Loaders sp.pdf
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdf
 
Introd to loaders_sp Adi.pdf
Introd to loaders_sp Adi.pdfIntrod to loaders_sp Adi.pdf
Introd to loaders_sp Adi.pdf
 
Assembler by ADI.pdf
Assembler by ADI.pdfAssembler by ADI.pdf
Assembler by ADI.pdf
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
VB PPT by ADI PART4.pdf
VB PPT by ADI PART4.pdfVB PPT by ADI PART4.pdf
VB PPT by ADI PART4.pdf
 
VB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdfVB PPT by ADI PART3.pdf
VB PPT by ADI PART3.pdf
 
WP Solutions- Adi.pdf
WP Solutions- Adi.pdfWP Solutions- Adi.pdf
WP Solutions- Adi.pdf
 
TOC Solutions-Adi.pdf
TOC Solutions-Adi.pdfTOC Solutions-Adi.pdf
TOC Solutions-Adi.pdf
 
SP Solutions -Adi.pdf
SP Solutions -Adi.pdfSP Solutions -Adi.pdf
SP Solutions -Adi.pdf
 
CNS Solutions-Adi.pdf
CNS Solutions-Adi.pdfCNS Solutions-Adi.pdf
CNS Solutions-Adi.pdf
 
VB PPT by ADI part-1.pdf
VB PPT by ADI part-1.pdfVB PPT by ADI part-1.pdf
VB PPT by ADI part-1.pdf
 
8085 microprocessor notes
8085 microprocessor notes8085 microprocessor notes
8085 microprocessor notes
 
Introduction to 8085_by_adi_ppt
Introduction to 8085_by_adi_pptIntroduction to 8085_by_adi_ppt
Introduction to 8085_by_adi_ppt
 

Recently uploaded

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 

Recently uploaded (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

VB PPT by ADI PART2.pdf

  • 3. INTRODUCTION Prof. K. Adisesha (Ph. D) 3 Programming using Visual Basic: Visual Basic uses building blocks such as Variables, Data Types, Procedures, Functions and Control Structures in its programming environment. This section concentrates on the programming fundamentals of Visual Basic with the blocks specified. ➢ MODULES : Code in Visual Basic is stored in the form of modules, which are of three type Form Modules, Standard Modules and Class Modules. ➢ Each module can contain: ❖ Declarations :May include constant, type, variable and DLL procedure declarations ❖ Procedures : A sub function, or property procedure that contain pieces of code that can be executed as a unit.
  • 4. DATA TYPES Prof. K. Adisesha (Ph. D) 4 Data types in Visual Basic: The compiler sets apart a number of bytes for each of the variable depending on the data type of holds Data types in Visual Basic ❖ Numeric ❖ String ❖ Date ❖ Boolean ❖ Variant
  • 5. Data type Size Range Byte 1 byte Byte Store integer values in the range of 0 - 255 Integer 2 bytes Integer Store integer values in the range of (-32,768) - (+ 32,767) Long 4 bytes Long Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468) Single 4 bytes Single Store floating point value in the range of (-3.4x10-38) - (+ 3.4x1038) Double 8 bytes Double Store large floating value which exceeding the single data type value Currency 8 bytes Currency store monetary values. It supports 4 digits to the right of decimal point and 15 digits to the left Decimal 14 bytes Decimal stores value with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001 DATA TYPES Prof. K. Adisesha (Ph. D) 5 ➢ Numeric Data type: The fundamental data types in Visual Basic including variant are integer, long, single, double, string, currency, byte and boolean.
  • 6. DATA TYPES Prof. K. Adisesha (Ph. D) 6 Data types : ➢ String: Use to store alphanumeric values. A variable length string can store approximately 4 billion characters. Uses storage size10 bytes + ➢ Date : Use to store date and time values. A variable declared as date type can store both date and time values and it can store date values 01/01/0100 up to 12/31/9999. It uses storage size of 8 bytes ➢ Boolean : Boolean data types hold either a true or false value. These are not stored as numeric values and cannot be used as such. Values are internally stored as -1 (True) and 0 (False) and any non-zero value is considered as true. Uses storage size of2 bytes ➢ Variant : In Visual Basic if we declare a variable without any data type by default the data type is assigned as variant data type.
  • 7. VARIABLES Prof. K. Adisesha (Ph. D) 7 Variables: Variables are the memory locations which are used to store values temporarily. A defined naming strategy has to be followed while naming a variable. ➢ A variable name must begin with an alphabet letter and should not exceed 255 characters. ➢ It must be unique within the same scope. ➢ The different ways of declaring variables in Visual Basic are listed below: ❖ Explicit Declaration ❖ Implicit Declaration ❖ Using Option Explicit statement
  • 8. VARIABLES Prof. K. Adisesha (Ph. D) 8 Variables: Variables are the memory locations which are used to store values temporarily. A defined naming strategy has to be followed while naming a variable. ➢ The following are the rules when naming the variables in Visual Basic: ❖ It must be less than 255 characters ❖ No spacing is allowed ❖ It must not begin with a number ❖ Period is not permitted ❖ Cannot use exclamation mark (!), or the characters @, &, $, # ❖ Cannot repeat names within the same level of scope.
  • 9. VARIABLES Prof. K. Adisesha (Ph. D) 9 Explicit variables declaration : Declaring a variable tells Visual Basic to reserve space in memory. to have more control over the variables, it is advisable to declare them explicitly. ➢ The variable can have different names and different types of values. ➢ The dim is keyword in visual Basic and has language specific meaning. ➢ Syntax for Declaring Variable Dim VaribaleName As DataType ➢ Example : Dim Regno as integer Dim Myname as string
  • 10. VARIABLES Prof. K. Adisesha (Ph. D) 10 Implicit variables declaration : 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. ➢ It may be convenient to declare variables implicitly, but it can lead to errors that may not be recognized at run time ➢ Syntax for Declaring Variable Dim str1,str2 Str1= “Implicit Declaration” Str2= Intcount + 1
  • 11. VARIABLES Prof. K. Adisesha (Ph. D) 11 Option Explicit variables declaration : This forces the user to declare all the variables. The Option Explicit statement checks in the module for usage of any undeclared variables and reports an error to the user. ➢ The user can thus rectify the error on seeing this error message. ➢ The Option Explicit statement can be explicitly placed in the general declaration section of each module using the following steps. ❖ Click Options item in the Tools menu ❖ Click the Editor tab in the Options dialog box ❖ Check Require Variable Declaration option and then click the OK button
  • 12. VARIABLES Prof. K. Adisesha (Ph. D) 12 Example: Program to find sum and average of two numbers
  • 13. VARIABLES Prof. K. Adisesha (Ph. D) 13 Scope of the variable: The scope of variable determines where you can access that variable in your code. ➢ If a variable is in scope you can read or set its value. ➢ If it is out of scope you will not be able to access it. ➢ Types of scope for variables in visual basic ❖ Global scope: Global variables are in scope anywhere in your application ❖ Module scope :Module level variables are in scope anywhere within the module where they are declared ❖ Local scope : Local variables are only in scope within the procedure where they are declared.
  • 14. Variables Prof. K. Adisesha (Ph. D) 14 Scope of the variable: Types of scope for variables in visual basic ➢ Local Variables: A local variable is one that is declared inside a procedure. This variable is only available to the code inside the procedure. Dim sum As Integer ➢ Static Variables: Static variables are not reinitialized each time Visual basic invokes a procedure and therefore retains or preserves value even when a procedure ends. Static intPermanent As Integer ➢ Module Level Variables: A module level variable is available to all the procedures in the module. They are declared using the Public or the Private keyword. these variables are useful for sharing data among procedures in the same module. Public CustomerName As String
  • 15. VARIABLES Prof. K. Adisesha (Ph. D) 15 Local Variables: A local variable is one that is declared inside a procedure. This variable is only available to the code inside the procedure and can be declared using the Dim statements. Dim sum As Integer ➢ The local variables exist as long as the procedure in which they are declared, is executing. ➢ Once a procedure is executed, the values of its local variables are lost and the memory used by these variables is freed and can be reclaimed. ➢ Variables that are declared with keyword Dim exist only as long as the procedure is being executed.
  • 16. VARIABLES Prof. K. Adisesha (Ph. D) 16 Static Variable: Static variables are not reinitialized each time Visual Invokes a procedure and therefore retains or preserves value even when a procedure ends. These static variables are also ideal for making controls alternately visible or invisible. ➢ A static variable is declared as given below. Static intPermanent As Integer ➢ Variables have a lifetime in addition to scope. ➢ The value of a local variable can be preserved using the Static keyword. Private Sub Command1_Click ( ) Static Counter As Integer End Sub
  • 17. VARIABLES Prof. K. Adisesha (Ph. D) 17 Module Level Variable: A module level variable is available to all the procedures in the module. They are declared using the Public or the Private keyword. If you declare a variable using a Private or a Dim statement in the declaration section of a module—a standard BAS module, a form module, a class module, and so on. ➢ A Private module-level variables are visible only from within the module they belong to and can't be accessed from the outside. these variables are useful for sharing data among procedures in the same module: Private LoginTime As Date ' A private module-level variable ➢ A Public module-level variable that can be accessed by all procedures in the module to share data and that also can be accessed from outside the module.
  • 18. VARIABLES Prof. K. Adisesha (Ph. D) 18 Assigning Values to Variables: After declaring various variables using Dim statements,we can assign values to variables. ➢ Example: ❖ firstNumber=100 ❖ secondNumber=firstNumber-99 ❖ userName=“K Adisesha" ❖ userpass.Text = password ❖ Label1.Visible = True ❖ Command1.Visible = false ❖ Label4.Caption = textbox1.Text ❖ ThirdNumber = Val(usernum1.Text)
  • 19. CONSTANTS Prof. K. Adisesha (Ph. D) 19 Constants in Visual Basic: Constant also store values, but as the name implies, those values remains constant throughout the execution of an application. ➢ Using constants can make your code more readable by providing meaningful names instead of numbers. ➢ There are a number of built –in constants in Visual Basic. ➢ There are two sources for constants: ❖ System-defined constants : are provided by applications and controls. Visual Basic constants are listed in the Visual Basic (VB). Form1.WindowState=value ❖ User-defined constants: are declared using the Const statement. It is a space in memory filled with fixed value that will not be changed. Const constant_name = value
  • 20. OPERATORS Prof. K. Adisesha (Ph. D) 20 Operators in Visual Basic: An operator is a special symbol which indicates a certain process is carried out. Operators in programming languages are taken from mathematics. ➢ The operators are used to process data. ➢ Types of operators in Visual Basic: ❖ Arithmetical operators ❖ Relational operators ❖ Logical operators.
  • 21. OPERATORS Prof. K. Adisesha (Ph. D) 21 ARITHMETICAL OPERATORS: Arithmetic operators are used to perform many of the familiar arithmetic operations that involve the calculation of numeric values represented by literals, variables, other expressions, function and property calls, and constants.
  • 22. OPERATORS Prof. K. Adisesha (Ph. D) 22 RELATIONAL OPERATORS: Comparison operators are used for Decision Making or compare two expressions and return a Boolean value that represents the relationship of their values. ➢ It uses If/Then structure ➢ Allows a program to make decision based on the truth or falsity of some expression Condition: ➢ The expression in an If/Then structure ❖ If the condition is true, the statement in the body of the structure executes ➢ Conditions can be formed by using ❖ Equality operators ❖ Relational operators
  • 23. OPERATORS Prof. K. Adisesha (Ph. D) 23 RELATIONAL OPERATORS: Comparison operators compare two expressions and return a Boolean value that represents the relationship of their values. There are operators for comparing numeric values, operators for comparing strings, and operators for comparing objects.. Operators Description Example Result > Greater than 10>8 True < Less than 10<8 False >= Greater than or equal to 10>=8 True <= Less than or equal to 10<=8 False == Equal to 10==8 false <> Not Equal to 10<>8 True
  • 24. OPERATORS Prof. K. Adisesha (Ph. D) 24 LOGICAL OPERATORS: In addition to conditional operators, there are a few logical operators which offer added power to the VB programs. ➢ Logical operators compare Boolean expressions and return a Boolean result. ➢ Some of these operators can also perform bitwise logical operations on integral values. Operators Description OR OR Operation will be true if either of the operands is true AND Operation will be true only if both the operands are true XOR One side or other must be true but not both NOT Negates true
  • 25. BUILT IN FUNCTIONS Prof. K. Adisesha (Ph. D) 25 BUILT IN FUNCTIONS: Many built in functions are offered by Visual basic under various categories. ➢ These functions return a value. ➢ Types of built in functions in VB are: ❖ Date and Time function ❖ Format function ❖ String function ❖ Numeric function
  • 26. BUILT IN FUNCTIONS Prof. K. Adisesha (Ph. D) 26 BUILT IN FUNCTIONS: Date and Time function: Use to store date and time values. A variable declared as date type can store both date and time values and it can store date values 01/01/0100 up to 12/31/9999. Time between 0:00:00 and 23:59:59. It uses storage size of 8 bytes Year Year(now) Month Month(now) Day Day(now) Weekday Weekday(now) Hour Hour(now) Minute Minute(now) Second Second(now)
  • 27. BUILT IN FUNCTIONS Prof. K. Adisesha (Ph. D) 27 BUILT IN FUNCTIONS: Format function & String functions: Use to convert values in other formatted which are convenient for user to use in application.
  • 28. CONVERSION Prof. K. Adisesha (Ph. D) 28 DATA TYPE CONVERSION: Visual Basic functions either to convert a string into an integer or vice versa and many more conversion functions. Conversion To Function Description Boolean Cbool The function Cbool converts any data type to Boolean 0 or 1 Byte Cbyte The function Cbyte converts any data type to Byte Currency Ccur The function Ccur converts any data type to currency Date Cdate The function Cdate converts any data type to date. Decimals Cdec The function Cdec converts any data type to decimal Value Cval The CVal function is used to convert string to double- precision numbers.
  • 29. Discussion Prof. K. Adisesha (Ph. D) 29 Queries ? Prof. K. Adisesha 9449081542