I thought <> works on strings? no?

M

mike

I've got some code like this:


gametype_id = Request.Form("gametype_id")
response.write "<br>gametype_id from form>" & gametype_id & "<"
response.write "<br>gametype_id from database>" &
rs_state("gametype_id") & "<"

if gametype_id = "" then
gametype_id = rs_state("gametype_id") 'could be NULL and make
gametype_id NULL
else
'the gametype from the form is not empty or NULL, so consider
updating the database record

'strComp returns -1 if the first value is smaller, a 0 if they're
equal, a 1 if the second value is smaller, or Null if either input is
Null.
'if strComp(gametype_id, rs_state("gametype_id"), vbTextCompare) <>
0 then
'nothing

if gametype_id <> rs_state("gametype_id") then
response.write "<br>updating gametype_id"
sql = "update maxminisuser set gametype_id = " & gametype_id & "
where userid =" & userid
conn.execute sql, , 129
end if
end if


ok now when I run the page I get this:

gametype_id from form>1<
gametype_id from database>1<
updating gametype_id <------WHY is this happening??

if I have two strings both equaling "1" as printed out above then why
does the line:

if gametype_id <> rs_state("gametype_id") then...

evaluate as true?????

<> is not equal to, as far as I know this works on strings??

when I use if strComp then it performs as expected, however <> is more
logical and readable and I want to understand why it is happening.

On the same page I have this statement:
if "1" = "1" then response.write "<br>1=1"
and it writes 1=1

when I do this
if "1" <> "1" then
response.write "1<>1"
end if

then it doesnt write anything
?????

so whats the difference between that line and
if gametype_id <> rs_state("gametype_id")
when both expressions printed out as "1" just before its evaluated??

soooo confused. What am I missing here???

-Mike
 
E

Egbert Nierop \(MVP for IIS\)

mike said:
I've got some code like this:


gametype_id = Request.Form("gametype_id")
response.write "<br>gametype_id from form>" & gametype_id & "<"
response.write "<br>gametype_id from database>" &
rs_state("gametype_id") & "<"

You should not write < or > to a HTML form because it will be interpreted by
a browser to be a tag.
so write &lt; resp &gt; for said:
if gametype_id = "" then
gametype_id = rs_state("gametype_id") 'could be NULL and make
gametype_id NULL
else
'the gametype from the form is not empty or NULL, so consider
updating the database record

'strComp returns -1 if the first value is smaller, a 0 if they're
equal, a 1 if the second value is smaller, or Null if either input is
Null.
'if strComp(gametype_id, rs_state("gametype_id"), vbTextCompare) <>
0 then
'nothing

if gametype_id <> rs_state("gametype_id") then
response.write "<br>updating gametype_id"
sql = "update maxminisuser set gametype_id = " & gametype_id & "
where userid =" & userid
conn.execute sql, , 129
end if
end if


ok now when I run the page I get this:

gametype_id from form>1<
gametype_id from database>1<
updating gametype_id <------WHY is this happening??

if I have two strings both equaling "1" as printed out above then why
does the line:

if gametype_id <> rs_state("gametype_id") then...

evaluate as true?????

<> is not equal to, as far as I know this works on strings??

when I use if strComp then it performs as expected, however <> is more
logical and readable and I want to understand why it is happening.

On the same page I have this statement:
if "1" = "1" then response.write "<br>1=1"
and it writes 1=1

when I do this
if "1" <> "1" then
response.write "1<>1"
end if

then it doesnt write anything
?????

so whats the difference between that line and
if gametype_id <> rs_state("gametype_id")
when both expressions printed out as "1" just before its evaluated??

the datatypes differ. So use
if clng(gametype_id ) <> rs_state("gametype_id") etc

or use CStr to make them string for comparision (not sure what datatype you
compare).
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top