ASP comparison question...

K

K

hi guys,


I am doing this here:

dim i
dim j

i = 10
j = 10

If i = j then

But it is giving me a false result...

Any ways to do this comparison so it gives me the proprer result?

Thanx.
 
R

Ray at

Are you sure this is all there is to it? Just that code alone should return
true, but if you're assinging i and j by some other means, it's likely that
one of them is a string and one is an integer, or something along those
lines. Doing this will take care of it though:

If CInt(i) = CInt(j) Then...


Depending on what kind of values you're using, you may want CLng to avoid an
overflow, i.e.
i = 32938493
j = 32938493

If CInt(i) = CInt(j) Then
'''Will cause an overflow
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbsvariables.asp

Ray at work
 
B

Bob Barrows

K said:
hi guys,


I am doing this here:

dim i
dim j

i = 10
j = 10

If i = j then

But it is giving me a false result...

Any ways to do this comparison so it gives me the proprer result?

Thanx.
Well, I can't reproduce your error.

This:
dim i
dim j

i = 10
j = 10

If i = j then
Response.Write "Equal"
else
Response.Write "Not Equal"
end if
Response.End

gives this result:
Equal

Suggestion: force both variable to the same data subtype:
i=cint(10)
j=cint(10)

HTH,
Bob Barrows
 
K

K

I am actually doi ng this:
i = request.form("var1")
j = request.form("var2")

And later, I do;

If i = j then
response.write
Else
response.write
End If

when I try =" or ,+, one return true, the other one false.
So I guess it is comparing the value in itself and not what it holds.

If I do Cint(j) I will get the actual value of the letter won't I?

Thx.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,207
Latest member
HelenaCani

Latest Threads

Top