I'm often stuck working with ASP and wishing I were working with PHP. PHP has a great deal of methods available that make life a lot easier. And in ASP you find yourself writing custom functions to do something that would be trivial in a better language.
Checking to see if a value exists within an array is one example. ASP does not offer any quick or easy solution. In fact, ASP is pretty much a nightmare when it comes to working with arrays. It's usually easier to use scripting dictionaries.
In order to check an array for a given value you can implement the following function.Function has(arr, val)
has = False
dim v : For Each v In arr
If val = v Then
has = True
End If
Next
End Function
Now you can do the following.If has(Array(2, 4, 6, 8), 4) = True Then
Response.Write "Hello"
End If
' Will write "Hello"
If has(Array(1, 3, 5, 7, 9), 4) = True Then
Response.Write "World!"
End If
' Will not write
This makes If statements a lot cleaner and easier to work with.
-
Array Has Function in ASP
1 Comment Posted on October 19th, 2009
1 Comment
-
Vim
Oct 21, 2009
I'm a newbie when it comes to understanding asp, would be great to see a post that features of basic functions within ASP explaining what they do, would somebody be able to make post for ASP dummies?
Leave a Comment
-
You
Sep 7, 2010