Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts

    inarray - how many times

    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

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    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
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    120
    Thanks
    0
    Thanked 3 Times in 3 Posts
    cause you'll never see the total. Move the response.write out of the for..next loop

    HTH, Tom


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •