String comparison error that I cannot track

Discussion in 'Javascript' started by bjjnova, Apr 25, 2006.

  1. bjjnova

    bjjnova Guest

    I have the following string comparison that is throwing an error I
    cannot find ( I will include my attempts to trace the error)

    In the line following the asterisks, written as I have below, a true is
    always returned and the printed msg appears that the 2 variables are
    not equal. This happens even when the print statement writes out,
    "Change Doc Types TASK and TASK are not equal". (So, even when I test
    each variable separately and it evaluates to "TASK", I still get a true
    on the first condition telling me that "TASK" and "TASK" are not
    equal).

    If I test by setting either variable to the thing I am testing for
    (e.g., "TASK") the first test evaluates to false and the else statement
    is executed (this is the expected result).

    If I change the condition to read

    if (vTODChgDocName == "TASK" && vMSBChgDocName != "TASK") the first
    condition evaluates to false, and the else executes.

    The "error" only occurs when I am testing vTODChgDocName against
    vMSBChgDocName.

    CODE:

    for (var vTODChgDocIterator = vTODChgDocCollection.iterator();
    vTODChgDocIterator.hasNext(); )
    {
    var vTODChgDocPointer = vTODChgDocIterator.next()
    vTODChgDoc = vTODChgDocCollection.get(vTODChgDocPointer)
    var vTODChgDocName = vTODChgDoc.name
    var vMSBChgDocName = childType.name
    print ("vTODChgDoc.name = " + vTODChgDocName + " , vMSBChgDocName = " +
    vMSBChgDocName)

    // ******* error is occuring in the following line ********************
    if (vTODChgDocName != vMSBChgDocName)
    {

    print ("Change Doc Types " + vTODChgDocName + " and " + vMSBChgDocName
    + " are not equal\n")

    }
    else
    {
    print ("Found " + vTODChgDocName + " in TOD")
    vTODChgDocFound = 1 }
    }
     
    bjjnova, Apr 25, 2006
    #1
    1. Advertising

  2. In article <>,
    bjjnova <> writes
    >I have the following string comparison that is throwing an error I
    >cannot find ( I will include my attempts to trace the error)
    >
    >In the line following the asterisks, written as I have below, a true is
    >always returned and the printed msg appears that the 2 variables are
    >not equal. This happens even when the print statement writes out,
    >"Change Doc Types TASK and TASK are not equal". (So, even when I test
    >each variable separately and it evaluates to "TASK", I still get a true
    >on the first condition telling me that "TASK" and "TASK" are not
    >equal).
    >
    >If I test by setting either variable to the thing I am testing for
    >(e.g., "TASK") the first test evaluates to false and the else statement
    >is executed (this is the expected result).
    >
    >If I change the condition to read
    >
    >if (vTODChgDocName == "TASK" && vMSBChgDocName != "TASK") the first
    >condition evaluates to false, and the else executes.
    >
    >The "error" only occurs when I am testing vTODChgDocName against
    >vMSBChgDocName.
    >
    >CODE:
    >
    >for (var vTODChgDocIterator = vTODChgDocCollection.iterator();
    >vTODChgDocIterator.hasNext(); )
    >{
    >var vTODChgDocPointer = vTODChgDocIterator.next()
    >vTODChgDoc = vTODChgDocCollection.get(vTODChgDocPointer)
    >var vTODChgDocName = vTODChgDoc.name
    >var vMSBChgDocName = childType.name


    Are the names String *objects*, as opposed to primitive string values ?
    If they are, then ...

    >print ("vTODChgDoc.name = " + vTODChgDocName + " , vMSBChgDocName = " +
    >vMSBChgDocName)
    >
    >// ******* error is occuring in the following line ********************
    >if (vTODChgDocName != vMSBChgDocName)


    .... change this to

    if (vTODChgDocName.valueOf() != vMSBChgDocName.valueOf())

    I expect you know why; if not just ask.

    >{
    >
    >print ("Change Doc Types " + vTODChgDocName + " and " + vMSBChgDocName
    >+ " are not equal\n")
    >
    >}
    >else
    >{
    >print ("Found " + vTODChgDocName + " in TOD")
    > vTODChgDocFound = 1 }
    > }


    --
    John Harris
     
    John G Harris, Apr 25, 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. =?Utf-8?B?Sm9u?=

    Track an error down

    =?Utf-8?B?Sm9u?=, Jul 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    341
    Jon Paal
    Jul 13, 2006
  2. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,339
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  3. Replies:
    21
    Views:
    1,453
    Alex Vinokur
    Aug 18, 2007
  4. Smithers
    Replies:
    12
    Views:
    1,208
    Ben Voigt [C++ MVP]
    Jul 7, 2009
  5. Deepu
    Replies:
    1
    Views:
    267
    ccc31807
    Feb 7, 2011
Loading...

Share This Page