SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
VISUAL BASIC FOR
APPLICATIONS WITH
EXCEL
 Variables and data types



Constants



Simple input and output



String functions


Declaring Variables :



To declare a variable, use a Dim (short for Dimension) statement.



Dim myVar As Integer



The name of the variable is myVar.
Note :- The name must begin with an alphabetic character and cannot exceed 255

characters or contain any spaces.



Use Option Explicit in the general declarations section of a module
window to force explicit variable declarations
Object and Standard Modules








Modules refer to a related set of declarations and procedures.
Each module will have a separate window in the VBA IDE and, depending on the
origination of the module, it will have different behavior with regard to variable
declarations.
This module will automatically contain all event procedures associated with the
worksheet Sheet1, and any ActiveX controls added to this worksheet.
A standard module must be added to the project via the Insert menu of the VBA IDE.
The object
module
for an Excel
worksheet.
Inserting a
standard module.
 Variable

Scope

Scope, in the context of variables, refers to the time when a
variable is visible or available to the program. When a variable
is in its scope, it can be accessed and/or anipulated. When a
variable is out of scope, it is unavailable—essentially invisible
to the program.
Private Sub Worksheet Activate()

Static myVar4 As Integer
myVar4 = myVar4 + 1
End Sub

In this procedure the variable myVar4 will increment its value by one with each call to the
procedure. If you replace the Static keyword with Dim, myVar4 will never exceed a value
of 1. Integer variables are initialized to a value of 0 at declaration.
Data Types




Data types define the kind of value that may be stored within the memory
allocated for a variable.
As with spreadsheet cells, there are numerous data types
Data Type

Storage Size

Range

Boolean

2 bytes

True or False

Integer

2 bytes

-32,768 to 32,767

Long

4 bytes

- 2,147,483,648 to
2,147,483,647

Single (floating-point)

4 bytes

- 3.402823E38 to
1.401298E-45 for negative
values; 1.401298E-45 to
3.402823E38 for positive
values

Currency

8-byte

922,337,203,685,477.580
8 to
922,337,203,685,477.580
7

Object

4 bytes

Any Object reference

String (variable-length

10 bytes + string length

0 to approximately 2
billion






Integer, long, single, and double.
A variable declared as an integer or long data type can hold whole numbers or nonfractional values within the specified ranges.
Common Mathematical Operators Used In VBA

Operation

Operator

Addition

+

Subtraction

-

Multiplication

*

Division

/

Exponential

^


Basically, any mathematical operation that can be performed on a number
can be performed on a numerical variable. The following are a few
examples:
Dim num1 As Integer
Dim num2 As Integer
Dim answer As Integer
num1 = 10
num2 = 5
answer = num1 + num2 ' answer Holds 15
answer = num1 num2 ' answer Holds 5
answer = num1 * num2 ' answer Holds 50
answer = num1 / num2 ' answer Holds 2
answer = num1 ^ 2 ' answer Holds 100
answer = 2 ^ num2 ' answer Holds 32






Variables with string data types are used to hold characters as
text. The characters can be numbers, letters, or special symbols
(for example, punctuation marks).
Basically, just about anything you can type on your keyboard can
be held within a string variable. To declare a variable with the
string data type, use the String keyword. To initialize a string
variable, place the string value within double quotation marks.
Dim myText As String
myText = “VBA is fun”

Dim myString As String * 8
myString = "ABCDEFGHIJKL“




Variant data types are analogous to the General category in the number format of a
spreadsheet cell in the Excel application.

Variables are declared as variants by using the keyword Variant, or by not specifying a
data type.



Dim myVar
Dim myVar2 As Variant



Variant type variables can hold any type of data except a fixed length string







Dim myVar As Integer
myVar = 10
myVar = "Testing"
The example above will generate a type mismatch error because an attempt is made to enter

the string "Testing" into an integer variable; however, if you change the variable myVar to a
variant, the code will execute and myVar will hold the string value "Testing" when all is complete.


The following code will run without error.



Dim myVar



myVar = 10



myVar = "Testing“

Boolean Data Types:
The Boolean data type holds the value true or false.

Declare and initialize a Boolean variable as follows:


Dim rollDice As Boolean



rollDice = False



Date Data Types



Variables of type date are actually stored as floating-point numbers with the integer portion
representing a date between 1 January 100 and 31 December 9999, and the decimal portion



representing a time between 0:00:00 and 23:59:59. The date data type is mostly a convenience



when you need to work with dates or times. Declare and initialize a Date variable as follows:



Dim currentDate As Date



currentDate = Now



A handful of VBA functions use variables of type date that add to this convenience. You will



see a couple of examples of date functions in the chapter project.




Constants allow you to assign a meaningful name to a number or string that will
make your code easier to read
Const PI = 3.14159





Dim circumference As Single
Dim diameter As Single
diameter =10.32
circumference = PI* diameter
Function Name

Returns

Str()

A string representation of a number

Val()

A numerical representation of a string

Trim()

A string with leading and trailing spaces
removed

Left()

A portion of a string beginning from the left
side

Right()

A portion of a string beginning from the
right side

Mid()

Any portion of a string

Contenu connexe

Tendances

Financial modeling sameh aljabli lecture 6
Financial modeling   sameh aljabli   lecture 6Financial modeling   sameh aljabli   lecture 6
Financial modeling sameh aljabli lecture 6Sameh Algabli
 
User define data type In Visual Basic
User define data type In Visual Basic User define data type In Visual Basic
User define data type In Visual Basic Shubham Dwivedi
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2Dan D'Urso
 
2016 Excel/VBA Notes
2016 Excel/VBA Notes2016 Excel/VBA Notes
2016 Excel/VBA NotesYang Ye
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in Indiaibinstitute0
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1guest38bf
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSSuraj Kumar
 
Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual BasicSangeetha Sg
 
Vba and macro creation (using excel)
Vba and macro creation (using excel)Vba and macro creation (using excel)
Vba and macro creation (using excel)Javier Morales Cauna
 
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
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programmingNgeam Soly
 
Part 12 built in function vb.net
Part 12 built in function vb.netPart 12 built in function vb.net
Part 12 built in function vb.netGirija Muscut
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Salim M
 

Tendances (19)

Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
Financial modeling sameh aljabli lecture 6
Financial modeling   sameh aljabli   lecture 6Financial modeling   sameh aljabli   lecture 6
Financial modeling sameh aljabli lecture 6
 
User define data type In Visual Basic
User define data type In Visual Basic User define data type In Visual Basic
User define data type In Visual Basic
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
 
Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
2016 Excel/VBA Notes
2016 Excel/VBA Notes2016 Excel/VBA Notes
2016 Excel/VBA Notes
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual Basic
 
Vba and macro creation (using excel)
Vba and macro creation (using excel)Vba and macro creation (using excel)
Vba and macro creation (using excel)
 
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
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
 
Part 12 built in function vb.net
Part 12 built in function vb.netPart 12 built in function vb.net
Part 12 built in function vb.net
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Excell vba
Excell vbaExcell vba
Excell vba
 
Excell vba
Excell vbaExcell vba
Excell vba
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
 

En vedette

Notes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculationsNotes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculationsWilliam Olivier
 
Programming inexcelvba anintroduction
Programming inexcelvba anintroductionProgramming inexcelvba anintroduction
Programming inexcelvba anintroductionOfun Emma
 
Intro macros in Excel 2007
Intro macros in Excel 2007Intro macros in Excel 2007
Intro macros in Excel 2007Hasrudin Tazep
 
Belajar macro excel 2007
Belajar macro excel 2007Belajar macro excel 2007
Belajar macro excel 2007doni sandra
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programmingRoger Argarin
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computersimran153
 
Introduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosIntroduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosExcel
 

En vedette (9)

Excel y visual basic
Excel y visual basicExcel y visual basic
Excel y visual basic
 
Notes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculationsNotes how to work with variables, constants and do calculations
Notes how to work with variables, constants and do calculations
 
Programming inexcelvba anintroduction
Programming inexcelvba anintroductionProgramming inexcelvba anintroduction
Programming inexcelvba anintroduction
 
Intro macros in Excel 2007
Intro macros in Excel 2007Intro macros in Excel 2007
Intro macros in Excel 2007
 
Belajar macro excel 2007
Belajar macro excel 2007Belajar macro excel 2007
Belajar macro excel 2007
 
Excel ch10
Excel ch10Excel ch10
Excel ch10
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
 
Introduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosIntroduction To Excel 2007 Macros
Introduction To Excel 2007 Macros
 

Similaire à Visual Basics for Application

Similaire à Visual Basics for Application (20)

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
 
Variables and calculations_chpt_4
Variables and calculations_chpt_4Variables and calculations_chpt_4
Variables and calculations_chpt_4
 
Qtp - Introduction to fundamentals of vbscript
Qtp - Introduction to fundamentals of vbscriptQtp - Introduction to fundamentals of vbscript
Qtp - Introduction to fundamentals of vbscript
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
Visual basic intoduction
Visual basic intoductionVisual basic intoduction
Visual basic intoduction
 
Vbscript
VbscriptVbscript
Vbscript
 
UNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCAUNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCA
 
VB Script Overview
VB Script OverviewVB Script Overview
VB Script Overview
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Concepts
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
Pj01 3-java-variable and data types
Pj01 3-java-variable and data typesPj01 3-java-variable and data types
Pj01 3-java-variable and data types
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 
datatypes_variables_constants
datatypes_variables_constantsdatatypes_variables_constants
datatypes_variables_constants
 

Plus de Raghu nath

Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)Raghu nath
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Selection sort
Selection sortSelection sort
Selection sortRaghu nath
 
Binary search
Binary search Binary search
Binary search Raghu nath
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)Raghu nath
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithmsRaghu nath
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp roleRaghu nath
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4Raghu nath
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3Raghu nath
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2Raghu nath
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1Raghu nath
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 

Plus de Raghu nath (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
 
MS WORD 2013
MS WORD 2013MS WORD 2013
MS WORD 2013
 
Msword
MswordMsword
Msword
 
Ms word
Ms wordMs word
Ms word
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary search
Binary search Binary search
Binary search
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Perl
PerlPerl
Perl
 

Dernier

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Dernier (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Visual Basics for Application

  • 2.  Variables and data types  Constants  Simple input and output  String functions
  • 3.  Declaring Variables :  To declare a variable, use a Dim (short for Dimension) statement.  Dim myVar As Integer  The name of the variable is myVar. Note :- The name must begin with an alphabetic character and cannot exceed 255 characters or contain any spaces.  Use Option Explicit in the general declarations section of a module window to force explicit variable declarations
  • 4. Object and Standard Modules     Modules refer to a related set of declarations and procedures. Each module will have a separate window in the VBA IDE and, depending on the origination of the module, it will have different behavior with regard to variable declarations. This module will automatically contain all event procedures associated with the worksheet Sheet1, and any ActiveX controls added to this worksheet. A standard module must be added to the project via the Insert menu of the VBA IDE.
  • 5. The object module for an Excel worksheet.
  • 7.  Variable Scope Scope, in the context of variables, refers to the time when a variable is visible or available to the program. When a variable is in its scope, it can be accessed and/or anipulated. When a variable is out of scope, it is unavailable—essentially invisible to the program. Private Sub Worksheet Activate() Static myVar4 As Integer myVar4 = myVar4 + 1 End Sub In this procedure the variable myVar4 will increment its value by one with each call to the procedure. If you replace the Static keyword with Dim, myVar4 will never exceed a value of 1. Integer variables are initialized to a value of 0 at declaration.
  • 8. Data Types   Data types define the kind of value that may be stored within the memory allocated for a variable. As with spreadsheet cells, there are numerous data types
  • 9. Data Type Storage Size Range Boolean 2 bytes True or False Integer 2 bytes -32,768 to 32,767 Long 4 bytes - 2,147,483,648 to 2,147,483,647 Single (floating-point) 4 bytes - 3.402823E38 to 1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values Currency 8-byte 922,337,203,685,477.580 8 to 922,337,203,685,477.580 7 Object 4 bytes Any Object reference String (variable-length 10 bytes + string length 0 to approximately 2 billion
  • 10.    Integer, long, single, and double. A variable declared as an integer or long data type can hold whole numbers or nonfractional values within the specified ranges. Common Mathematical Operators Used In VBA Operation Operator Addition + Subtraction - Multiplication * Division / Exponential ^
  • 11.  Basically, any mathematical operation that can be performed on a number can be performed on a numerical variable. The following are a few examples: Dim num1 As Integer Dim num2 As Integer Dim answer As Integer num1 = 10 num2 = 5 answer = num1 + num2 ' answer Holds 15 answer = num1 num2 ' answer Holds 5 answer = num1 * num2 ' answer Holds 50 answer = num1 / num2 ' answer Holds 2 answer = num1 ^ 2 ' answer Holds 100 answer = 2 ^ num2 ' answer Holds 32
  • 12.    Variables with string data types are used to hold characters as text. The characters can be numbers, letters, or special symbols (for example, punctuation marks). Basically, just about anything you can type on your keyboard can be held within a string variable. To declare a variable with the string data type, use the String keyword. To initialize a string variable, place the string value within double quotation marks. Dim myText As String myText = “VBA is fun” Dim myString As String * 8 myString = "ABCDEFGHIJKL“
  • 13.   Variant data types are analogous to the General category in the number format of a spreadsheet cell in the Excel application. Variables are declared as variants by using the keyword Variant, or by not specifying a data type.  Dim myVar Dim myVar2 As Variant  Variant type variables can hold any type of data except a fixed length string     Dim myVar As Integer myVar = 10 myVar = "Testing"
  • 14. The example above will generate a type mismatch error because an attempt is made to enter the string "Testing" into an integer variable; however, if you change the variable myVar to a variant, the code will execute and myVar will hold the string value "Testing" when all is complete.  The following code will run without error.  Dim myVar  myVar = 10  myVar = "Testing“ Boolean Data Types: The Boolean data type holds the value true or false. Declare and initialize a Boolean variable as follows:
  • 15.  Dim rollDice As Boolean  rollDice = False  Date Data Types  Variables of type date are actually stored as floating-point numbers with the integer portion representing a date between 1 January 100 and 31 December 9999, and the decimal portion  representing a time between 0:00:00 and 23:59:59. The date data type is mostly a convenience  when you need to work with dates or times. Declare and initialize a Date variable as follows:  Dim currentDate As Date  currentDate = Now  A handful of VBA functions use variables of type date that add to this convenience. You will  see a couple of examples of date functions in the chapter project.
  • 16.   Constants allow you to assign a meaningful name to a number or string that will make your code easier to read Const PI = 3.14159     Dim circumference As Single Dim diameter As Single diameter =10.32 circumference = PI* diameter
  • 17. Function Name Returns Str() A string representation of a number Val() A numerical representation of a string Trim() A string with leading and trailing spaces removed Left() A portion of a string beginning from the left side Right() A portion of a string beginning from the right side Mid() Any portion of a string