Sign in to follow this  

[web] [ASP] Searching through an array

Recommended Posts

I manually created an array will 2 values for now. I was wondering how I can search through it to check for a value?
Dim sUsers(1)
sUsers(0) = "CBrinker"
sUsers(1) = "AWilson"
I already tried using:
check = Array.BinarySearch(sUsers, GetLoginName)
But I get this error:
Microsoft VBScript runtime error '800a01a8' 

Object required: 'Array' 

/marketing/product/index.asp, line 19 
Which is that line. Help? =/

Share this post

Link to post
Share on other sites
Are you not using a database of any kind? It'd probably be better than hardcoding your users into the code. If you have to hardcode, at least have a separate usr_const.asp file that you include at the start of your file, otherwise it could be a nightmare to maintain!

Share this post

Link to post
Share on other sites
There is no method called BinarySearch as far as I know. A binary search will only work on a sorted list anyway. Unless you are going to sort your list, the only way to do it is to iterate through all of the elements until you find what you're looking for. If it's sorted then you can write a binary search yourself, or find a code snippet somewhere and copy it.

This is all you can do with the array object:
users = new Array("patrick", "brandon")

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this