Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > String comparison error that I cannot track

Reply
Thread Tools

String comparison error that I cannot track

 
 
bjjnova
Guest
Posts: n/a
 
      04-25-2006
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 }
}

 
Reply With Quote
 
 
 
 
John G Harris
Guest
Posts: n/a
 
      04-25-2006
In article <(E-Mail Removed) .com>,
bjjnova <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Comparison of 2 files and generating the output based on comparison Deepu Perl Misc 1 02-07-2011 03:09 PM
insert track reference in mp3 track D@Z Computer Support 1 05-02-2008 03:32 PM
Price Comparison Service. Best Deal. Special Coupon atBest-Price-Comparison.com rapee Digital Photography 0 03-14-2008 06:46 AM
Old certification track vs new certification track. Barkley Hughes MCAD 5 11-12-2006 02:41 PM



Advertisments