...

View Full Version : inarray - how many times



esthera
11-28-2007, 08:32 AM
i have the following function to determine if a string is in an array.
can someone help me fix it to instead of returning true/false it should return the amount of times it exists in the array. (and 0 if it doesn't exist)

Function InArray(strValue)
Dim i
For i = 0 to UBound(aracrust)
If selCriteria(i,1) = cstr(strValue) Then
InArray = TRUE
Exit Function
End If
Next
InArray = FALSE
End Function

shyam
11-28-2007, 10:32 AM
Function InArray(strValue)
Dim i
InArray = 0
For i = 0 to UBound(aracrust)
If selCriteria(i,1) = cstr(strValue) Then
InArray = InArray + 1
End If
Next
End Function

esthera
11-28-2007, 11:17 AM
i took it out of the function as it was erroring

but

InArray = 0
For i = 0 to UBound(aracrust)
If aracrust(i) = cstr(sacrust) Then
InArray = InArray + 1
response.write "<font color=red>" & sacrust & "found" & inarray
End If
Next

now if it exists it's always returning 1 and never larger - any idea why?

Whatever Jr.
12-04-2007, 12:24 PM
cause you'll never see the total. Move the response.write out of the for..next loop

HTH, Tom



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum