mercredi 25 janvier 2017

Searching array with an If Statement ASP

I have this function searching if a value exist through an array. Here's my function:

Function In_Array(iCountryID, iCountryArray)
In_Array = false
For i = 0 To UBound(iCountryArray)
    If iCountryArray(i) = iCountryID Then
        In_Array = true
        Exit Function
    End If
Next

What I'm doing is check if the value from iCountryID matches any value from the array. If iCountryID does exist in the array, then Exit the Function and continue. If iCountryID does not exist in the array, redirect to an error page (error.asp)

How and where do I include the redirect?

Response.Redirect "error.asp"

If I add an If Statement, it doesn't work:

If In_Array = false Then 
    Response.Redirect "error.asp"
End If

The value of the array may look like this: (99,115,218,305). If the value of iCountryID is 115, then exit the function and continue on. If iCountryID = 150, then redirect to error.asp.

Aucun commentaire:

Enregistrer un commentaire