I have an array and would like to find out the index of an element in that
when I know the actual value of the element.
I need to do it in VBScript, not in VB.
For example,
Lets assume that I have an array like follwing.
Dim MyArray1 (3)
MyArray1(0) = "Sunday"
MyArray1(1) = "Monday"
MyArray1(2) = "Tuesday"
Is there any method/fucntion/property that takes either 'Monday' as input
parameter and returns '1' ?
In another way, is there any equivalent method in VBScript similar to
'indexOf' method in Java Script??
Any help would be greatly appreciated.
Thanks,
Vasanthi
Also, you will have to loop through the array looking for a match..
Like (VB way):
Private Function IndexOf(Ary As Variant, strToMatch As String) As Long
'Default to an error code
IndexOf = -1
'Make sure an array was passed
If Not IsArray(Ary) Then Exit Function
'Check for matching index
Dim i As Long
For i = 0 To UBound(Ary)
If StrComp(strToMatch, Ary(i), vbTextCompare) = 0 Then
IndexOf = i
Exit For
End If
Next
End Function
VBScript way:
Private Function IndexOf(Ary, strToMatch)
'Default to an error code
IndexOf = -1
'Make sure an array was passed
If Not IsArray(Ary) Then Exit Function
'Check for matching index
Dim i As Long
For i = 0 To UBound(Ary)
If StrComp(strToMatch, Ary(i), vbTextCompare) = 0 Then
IndexOf = i
Exit For
End If
Next
End Function
--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
"Vasanthi" <Vasa...@discussions.microsoft.com> wrote in message
news:BC0796AF-D56B-4382...@microsoft.com...
Thanks for your reply.
I really don't want to loop through the array. I am intrested in using some
direct function/property.
Any ideas??
Thanks,
Vasanthi
--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
"Vasanthi" <Vasa...@discussions.microsoft.com> wrote in message
news:585DD5AE-5A8C-44DA...@microsoft.com...