Friday, January 22, 2016

VB Script Array Functions:

IsArray
Description: IsArray function is used to check whether a given variable is an array or not.
Syntax: IsArray(Variable_Name)
Return Type: A Boolean Value (True / False)
Example: Dim MyArray(10), MyVar
Value1 = IsArray(MyArray)
Msgbox Value1                 ‘will display True since MyArray is an Array.
Value2 = IsArray(MyVar)
Msgbox Value2                ‘will display False since MyVar is not an Array.              
-------------------------------------------------------------------------------------
Array
Description: Array function is used to get an Array variable reference to a variable.
Syntax: Array(Elements_List)
Return Type: An Array Variable
Example: Dim A
A = Array(10,20,30,40,50)
-------------------------------------------------------------------------------
LBound
Description: LBound functions is used to get the smallest subscript of an array variable which is always is zero.
Syntax: LBound(Array_Name)
Return Type: A Variant Value
Example: Dim MyArray(10)
MsgBox LBound(MyArray)    
------------------------------------------------------------------------------------
UBound
Description: UBound function is used to get the largest subscript of an Array variable.
Syntax: UBound(Array_Name)
Return Type: A Variant Value
Example1: Dim MyArray(10)
MsgBox UBound(MyArray)                      ‘Display 10
Example2: Dim Arr_Var = Array(10,20,30,40,50)
MsgBox UBound(Arr_Var)                       ‘Display 4
-------------------------------------------------------------------------------------
Join
Description: Join function is used to get a string by joining the Array elements with the specified delimiter.
Syntax: Join(Array_Name, Delimiter(Optional))  
Return Type: A String variable
Example: Dim MyArray, New_String
MyArray = Array(10,20,30,40)
New_String = Join(MyArray,”#”)
MsgBox New_String            ‘display 10#20#30#40
-------------------------------------------------------------------------------------
Split
Description: Split Function is used to get zero based index Array variable from a string based on the delimiter.
Syntax: Split(Var_String,Delimiter(Optional),Count(Optional),Compare(Optional))
Return Type: An Array Variable
Example: Dim Var_String, Var_Array
Var_String = “A#B#C#D”
Var_Array = Split(Var_String, “#”)
MsgBox Var_Array(0)                 ‘Display A
MsgBox Var_Array(1)                 ‘Display B
MsgBox Var_Array(2)                 ‘Display C
MsgBox Var_Array(3)                 ‘Display D

Note: Given examples may have some syntax errors.

No comments:

Post a Comment