Jump to content
  • Advertisement
Sign in to follow this  
chbrules

[web] Array Value Comparisons

This topic is 4888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I don't really see exactly what's wrong w/ my ASP here. I have a simple array that holds a couple username strings and all I want to do is compare it to the variable that gets the username from the server. It goes like so:
<%
'Access List for user logins for products DB
user_size = 2

Dim sUsers(2)
sUsers(0) = "CBrinker"
sUsers(1) = "AWilson"
%>
'Check Username
auth = 0

Do While Not user_size > -1
	If GetLoginName = sUsers(user_size) then
		auth = 1
        Exit Do '<-- break the LOOP
	Else
		user_size = user_size - 1
	End If
Loop
GetLoginName already holds the proper value of the user's name, I've checked that, but I don't see where my loop is going wrong doing the checks. Both values come out when I do a Response.Write(), but other then that it's not comparing properly. Any idea why? =/

Share this post


Link to post
Share on other sites
Advertisement
It will never enter the loop, because of this:
Do While Not user_size > -1

You set: user_size = 2
Then you check: Not user_size > -1

Not user_size > -1 eq.
Not (2 > -1) eq.
Not (true) eq.
False [smile]

Also, but this isn't causing the problem here, the array runs for 0 to 1, and the first loop would check sUsers(user_size) eq. sUsers(2), which is out of bounds.

Share this post


Link to post
Share on other sites
I think you should try this code


<%
'Access List for user logins for products DB

Dim sUsers(2)
sUsers(0) = "CBrinker"
sUsers(1) = "AWilson"

user_size = UBound(sUsers)

auth = 0

Do While user_size > -1
If GetLoginName = sUsers(user_size) then
auth = 1
Exit Do '<-- break the LOOP
Else
user_size = user_size - 1
End If
Loop



or the better way is


'Access List for user logins for products DB

Dim sUsers(2)
sUsers(0) = "CBrinker"
sUsers(1) = "AWilson"

user_size = UBound(sUsers)

auth = 0

For i = 0 To user_size
If GetLoginName = sUsers(user_size) then
auth = 1
Exit For
End If
Next


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!