I thought <> works on strings? no?

Discussion in 'ASP General' started by mike, Jul 29, 2006.

  1. mike

    mike Guest

    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
     
    mike, Jul 29, 2006
    #1
    1. Advertising

  2. "mike" <> wrote in message
    news:...
    > 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 < and >

    > 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).
     
    Egbert Nierop \(MVP for IIS\), Jul 29, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    1
    Views:
    3,636
    Ralf Hildebrandt
    Aug 8, 2005
  2. F. GEIGER
    Replies:
    3
    Views:
    776
    F. GEIGER
    Aug 6, 2004
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    767
    Malcolm
    Jun 24, 2006
  4. Alexander Burger

    getMethod() works and works not

    Alexander Burger, Nov 27, 2010, in forum: Java
    Replies:
    25
    Views:
    1,766
    Alexander Burger
    Nov 29, 2010
  5. abargaddon
    Replies:
    1
    Views:
    197
    clintmazur
    Feb 4, 2008
Loading...

Share This Page