SlideShare a Scribd company logo
1 of 23
ARRAYS
What is an array?
• We know very well that a variable is a container to store a value.
Sometimes, developers are in a position to hold more than one value
in a single variable at a time. When a series of values is stored in a
single variable, then it is known as an array variable.
CREATING ARRAYS
• We can create arrays several ways, depending on whether they are
static or dynamic.
• Static arrays - Static arrays stay a fixed size throughout their lifetime—
that is, the index size remains constant. Thus, when we create a static
array, we must know how many items the array will contain
throughout its lifetime.
• Dynamic arrays – Suppose if we don't know the number of items or
don’t know that the array's index size will change, we need to create a
dynamic array. Dynamic arrays don't have a fixed index size. We can
increase or decrease the index size at any time.
Array Declaration and Assigning Values to an Array
Example 1:
option explicit
dim arr(3)
arr(0)=1
arr(1)="2"
arr(2)="sun"
arr(3) = #10/07/2013#
msgbox arr(0)
msgbox arr(1)
msgbox arr(2)
msgbox arr(3)
Example 2:
option explicit
Dim arr
arr=array("5",100,45,464)
msgbox arr(0)
msgbox arr(1)
msgbox arr(2)
msgbox arr(3)
Multi-Dimension Arrays
• Arrays are not just limited to single dimension and can have a maximum of 60 dimensions. Two-dimension
arrays are the most commonly used ones.
Example:
Option explicit
Dim arr(1,2) //2 rows and 3 columns
arr(0,0) = "A"
arr(0,1) = "B"
arr(0,2) = "C"
arr(1,0) = "Dr"
arr(1,1) = "E"
arr(1,2) = "F"
msgbox arr(0,0)
msgbox arr(0,1)
msgbox arr(0,2)
msgbox arr(1,0)
msgbox arr(1,1)
msgbox arr(1,2)
ReDim Statement
• ReDim Statement is used to declare dynamic-array variables and allocate or reallocate storage space.
Example:
option explicit
dim arr()
redim arr(5)
arr(0)=1
arr(1)=2
arr(2)=3
arr(3)=4
arr(4)=5
redim preserve arr(10)
arr(6)=7
msgbox arr(0)
msgbox arr(1)
msgbox arr(6)
redim preserve arr(4)
msgbox arr(0)
msgbox arr(1)
msgbox arr(2)
msgbox arr(3)
msgbox arr(4)
Array Methods
LBound Function
• The LBound Function returns the smallest subscript of the specified array.
Hence, LBound of an array is ZERO.
Example:
option explicit
dim arr(5)
arr(0)=1
arr(1)=2
arr(2)=3
arr(3)=4
arr(4)=5
msgbox lbound(arr)
UBound Function
The UBound Function returns the Largest subscript of the specified
array. Hence, this value corresponds to the size of the array.
Example:
option explicit
dim arr(5)
arr(0)=1
arr(1)=2
arr(2)=3
arr(3)=4
arr(4)=5
msgbox ubound(arr)
Split Function
• A Split Function returns an array that contains a specific number of values
split based on a Delimiter.
Example:
option explicit
dim arr,b,c,i
arr=split("sun & technology & integrators","&")
b=ubound(arr)
for i=0 to b
msgbox arr(i)
next
Join Function
• A Function, which returns a String that contains a specified number of
substrings in an array. This is an exact opposite function of Split Method.
Example:
option explicit
dim arr,b,c
arr=array("sun","technology","integrators")
b=join(arr)
msgbox b
c=join(arr,0)
msgbox c
Filter Function
A Filter Function, which returns a zero-based array that contains a subset of a
string array based on a specific filter criteria.
Example:
option explicit
Dim MyIndex
Dim MyArray (3)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Tuesday"
MyIndex = Filter(MyArray, "Mon")
msgbox myindex(0)
IsArray Function
The IsArray Function returns a Boolean value that indicates whether or NOT the
specified input variable is an array variable.
Example:
option explicit
dim a,b
a=array("Red","Blue","Yellow")
b = "12345"
msgbox isarray(a)
msgbox isarray(b)
Erase Function
The Erase Function is used to reset the values of fixed size arrays and free the memory of the
dynamic arrays.
Example:
option explicit
dim a(2)
a(0)="hello"
a(1)=22
a(2)=08
msgbox a(0)
msgbox a(1)
msgbox a(2)
erase a
msgbox a(0)
msgbox a(1)
msgbox a(2)
FUNCTIONS
What is a Function?
A function is a group of reusable code which can be called anywhere in your
program. This eliminates the need of writing same code over and over again.
This will enable programmers to divide a big program into a number of small and
manageable functions.
• Function Definition
Before we use a function, we need to define that particular function. The most
common way to define a function in VBScript is by using the Function keyword,
followed by a unique function name and it may or may not carry a list of
parameters and a statement with an End Function keyword
Example 1:
option explicit
Function Hello()
msgbox("Hello")
End Function
call hello()
Example2:
option explicit
Function Hello(name,age)
msgbox( name & " is " & age & " years old.")
End Function
call hello("vb",4)
Example3:
option explicit
Function sum(number1,number2)
sum = number1 + number2
End Function
Dim total
total = sum(100,9)
msgbox total
Sub-Procedures
Sub-Procedures are similar to functions but there are few differences.
• Sub-procedures DONOT Return a value while functions may or may not return
a value.
• Sub-procedures Can be called without call keyword.
• Sub-procedures are always enclosed within Sub and End Sub statements.
Example:
option explicit
sub Hello()
msgbox("Hello")
End sub
hello()
VBScript ByVal Parameters:
If ByVal is specified, then the arguments are sent as byvalue when the function or
procedure is called.
Example:
option explicit
Function fnadd(Byval num1, Byval num2)
num1 = 4
num2 = 5
End Function
Dim x,y,res
x=6
y=4
res= fnadd(x,y)
msgbox x
msgbox y
VBScript ByRef Parameters
If ByRef is specified, then the arguments are sent as a reference when the function or
procedure is called.
Example:
option explicit
Function fnadd(byRef num1,ByRef num2)
num1 = 4
num2 = 5
End Function
Dim x,y,res
x=6
y=4
res= fnadd(x,y)
msgbox x
msgbox y

More Related Content

What's hot (20)

Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
This pointer
This pointerThis pointer
This pointer
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Union In language C
Union In language CUnion In language C
Union In language C
 
Python functions
Python functionsPython functions
Python functions
 
python Function
python Function python Function
python Function
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use cases
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Typedef
TypedefTypedef
Typedef
 
Python list
Python listPython list
Python list
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
 

Viewers also liked (12)

D.O. 36 S. 2016
D.O. 36 S. 2016D.O. 36 S. 2016
D.O. 36 S. 2016
 
Un approccio civile al capitalismo fra utopia e realtà
Un approccio civile al capitalismo fra utopia e realtàUn approccio civile al capitalismo fra utopia e realtà
Un approccio civile al capitalismo fra utopia e realtà
 
에이스트레이더 월간 마케팅 보고서_초중고교육 온라인 마케팅 동향
에이스트레이더 월간 마케팅 보고서_초중고교육 온라인 마케팅 동향에이스트레이더 월간 마케팅 보고서_초중고교육 온라인 마케팅 동향
에이스트레이더 월간 마케팅 보고서_초중고교육 온라인 마케팅 동향
 
3Com CENTRO
3Com CENTRO3Com CENTRO
3Com CENTRO
 
Data Structure (Static Array)
Data Structure (Static Array)Data Structure (Static Array)
Data Structure (Static Array)
 
QTest
QTest QTest
QTest
 
Software testing
Software testingSoftware testing
Software testing
 
Selenium
SeleniumSelenium
Selenium
 
Extended Finite State Machine - EFSM
Extended Finite State Machine - EFSMExtended Finite State Machine - EFSM
Extended Finite State Machine - EFSM
 
Sikuli
SikuliSikuli
Sikuli
 
Devops
DevopsDevops
Devops
 
Jira
JiraJira
Jira
 

Similar to Array and functions

Basic vbscript for qtp
Basic vbscript for qtpBasic vbscript for qtp
Basic vbscript for qtpCuong Tran Van
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
C language presentation
C language presentationC language presentation
C language presentationbainspreet
 
VBScript in Software Testing
VBScript in Software TestingVBScript in Software Testing
VBScript in Software TestingFayis-QA
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoreambikavenkatesh2
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat SheetLaura Hughes
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...Maulik Borsaniya
 

Similar to Array and functions (20)

Basic vbscript for qtp
Basic vbscript for qtpBasic vbscript for qtp
Basic vbscript for qtp
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Array andfunction
Array andfunctionArray andfunction
Array andfunction
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
MA3696 Lecture 6
MA3696 Lecture 6MA3696 Lecture 6
MA3696 Lecture 6
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
C language presentation
C language presentationC language presentation
C language presentation
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
VB Script
VB ScriptVB Script
VB Script
 
VBScript in Software Testing
VBScript in Software TestingVBScript in Software Testing
VBScript in Software Testing
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat Sheet
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
 

More from Sun Technlogies (14)

Silk Performer Presentation v1
Silk Performer Presentation v1Silk Performer Presentation v1
Silk Performer Presentation v1
 
Selenium
SeleniumSelenium
Selenium
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
XPATH
XPATHXPATH
XPATH
 
Path Testing
Path TestingPath Testing
Path Testing
 
Maven and ANT
Maven and ANTMaven and ANT
Maven and ANT
 
HTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts BasicsHTML, CSS and Java Scripts Basics
HTML, CSS and Java Scripts Basics
 
Jmeter
JmeterJmeter
Jmeter
 
Javascript
JavascriptJavascript
Javascript
 
HyperText Markup Language - HTML
HyperText Markup Language - HTMLHyperText Markup Language - HTML
HyperText Markup Language - HTML
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
Core java
Core javaCore java
Core java
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
 
Mobile Application Testing
Mobile Application TestingMobile Application Testing
Mobile Application Testing
 

Recently uploaded

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Recently uploaded (20)

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

Array and functions

  • 2. What is an array? • We know very well that a variable is a container to store a value. Sometimes, developers are in a position to hold more than one value in a single variable at a time. When a series of values is stored in a single variable, then it is known as an array variable.
  • 3. CREATING ARRAYS • We can create arrays several ways, depending on whether they are static or dynamic. • Static arrays - Static arrays stay a fixed size throughout their lifetime— that is, the index size remains constant. Thus, when we create a static array, we must know how many items the array will contain throughout its lifetime. • Dynamic arrays – Suppose if we don't know the number of items or don’t know that the array's index size will change, we need to create a dynamic array. Dynamic arrays don't have a fixed index size. We can increase or decrease the index size at any time.
  • 4. Array Declaration and Assigning Values to an Array Example 1: option explicit dim arr(3) arr(0)=1 arr(1)="2" arr(2)="sun" arr(3) = #10/07/2013# msgbox arr(0) msgbox arr(1) msgbox arr(2) msgbox arr(3)
  • 5. Example 2: option explicit Dim arr arr=array("5",100,45,464) msgbox arr(0) msgbox arr(1) msgbox arr(2) msgbox arr(3)
  • 6. Multi-Dimension Arrays • Arrays are not just limited to single dimension and can have a maximum of 60 dimensions. Two-dimension arrays are the most commonly used ones. Example: Option explicit Dim arr(1,2) //2 rows and 3 columns arr(0,0) = "A" arr(0,1) = "B" arr(0,2) = "C" arr(1,0) = "Dr" arr(1,1) = "E" arr(1,2) = "F" msgbox arr(0,0) msgbox arr(0,1) msgbox arr(0,2) msgbox arr(1,0) msgbox arr(1,1) msgbox arr(1,2)
  • 7. ReDim Statement • ReDim Statement is used to declare dynamic-array variables and allocate or reallocate storage space. Example: option explicit dim arr() redim arr(5) arr(0)=1 arr(1)=2 arr(2)=3 arr(3)=4 arr(4)=5 redim preserve arr(10) arr(6)=7 msgbox arr(0) msgbox arr(1) msgbox arr(6) redim preserve arr(4) msgbox arr(0) msgbox arr(1) msgbox arr(2) msgbox arr(3) msgbox arr(4)
  • 8. Array Methods LBound Function • The LBound Function returns the smallest subscript of the specified array. Hence, LBound of an array is ZERO. Example: option explicit dim arr(5) arr(0)=1 arr(1)=2 arr(2)=3 arr(3)=4 arr(4)=5 msgbox lbound(arr)
  • 9. UBound Function The UBound Function returns the Largest subscript of the specified array. Hence, this value corresponds to the size of the array. Example: option explicit dim arr(5) arr(0)=1 arr(1)=2 arr(2)=3 arr(3)=4 arr(4)=5 msgbox ubound(arr)
  • 10. Split Function • A Split Function returns an array that contains a specific number of values split based on a Delimiter. Example: option explicit dim arr,b,c,i arr=split("sun & technology & integrators","&") b=ubound(arr) for i=0 to b msgbox arr(i) next
  • 11. Join Function • A Function, which returns a String that contains a specified number of substrings in an array. This is an exact opposite function of Split Method. Example: option explicit dim arr,b,c arr=array("sun","technology","integrators") b=join(arr) msgbox b c=join(arr,0) msgbox c
  • 12. Filter Function A Filter Function, which returns a zero-based array that contains a subset of a string array based on a specific filter criteria. Example: option explicit Dim MyIndex Dim MyArray (3) MyArray(0) = "Sunday" MyArray(1) = "Monday" MyArray(2) = "Tuesday" MyIndex = Filter(MyArray, "Mon") msgbox myindex(0)
  • 13. IsArray Function The IsArray Function returns a Boolean value that indicates whether or NOT the specified input variable is an array variable. Example: option explicit dim a,b a=array("Red","Blue","Yellow") b = "12345" msgbox isarray(a) msgbox isarray(b)
  • 14. Erase Function The Erase Function is used to reset the values of fixed size arrays and free the memory of the dynamic arrays. Example: option explicit dim a(2) a(0)="hello" a(1)=22 a(2)=08 msgbox a(0) msgbox a(1) msgbox a(2) erase a msgbox a(0) msgbox a(1) msgbox a(2)
  • 16. What is a Function? A function is a group of reusable code which can be called anywhere in your program. This eliminates the need of writing same code over and over again. This will enable programmers to divide a big program into a number of small and manageable functions. • Function Definition Before we use a function, we need to define that particular function. The most common way to define a function in VBScript is by using the Function keyword, followed by a unique function name and it may or may not carry a list of parameters and a statement with an End Function keyword
  • 17. Example 1: option explicit Function Hello() msgbox("Hello") End Function call hello()
  • 18. Example2: option explicit Function Hello(name,age) msgbox( name & " is " & age & " years old.") End Function call hello("vb",4)
  • 19. Example3: option explicit Function sum(number1,number2) sum = number1 + number2 End Function Dim total total = sum(100,9) msgbox total
  • 20. Sub-Procedures Sub-Procedures are similar to functions but there are few differences. • Sub-procedures DONOT Return a value while functions may or may not return a value. • Sub-procedures Can be called without call keyword. • Sub-procedures are always enclosed within Sub and End Sub statements.
  • 22. VBScript ByVal Parameters: If ByVal is specified, then the arguments are sent as byvalue when the function or procedure is called. Example: option explicit Function fnadd(Byval num1, Byval num2) num1 = 4 num2 = 5 End Function Dim x,y,res x=6 y=4 res= fnadd(x,y) msgbox x msgbox y
  • 23. VBScript ByRef Parameters If ByRef is specified, then the arguments are sent as a reference when the function or procedure is called. Example: option explicit Function fnadd(byRef num1,ByRef num2) num1 = 4 num2 = 5 End Function Dim x,y,res x=6 y=4 res= fnadd(x,y) msgbox x msgbox y