Page 1 of 1

Fonction "COMPARE"

Posted: Mon Mar 26, 2012 5:52 pm
by waligator
Hi all,

I think it is a bug in the "COMPARE" string!

If the variable "Test" is rec, with writing below, the answer must be 0. As the third parameter is "1".
Return = Compare$ (Test,"REC",1)

With V5, the response is reversed.

Can you check

thank you
Steve

Re: Fonction "COMPARE"

Posted: Mon Mar 26, 2012 9:20 pm
by JonnyW
Good evening. If the variable Test="rec" then this should return '1' - the flag is for 'case insensitive' according to the help file so "REC" and "rec" are seen as the same.

However I have only tested this in simulation but have looked at the C code for the compare and this is as expected. Can you confirm simulation is where the issue is or is it on the chip?

Jonny

Re: Fonction "COMPARE"

Posted: Tue Mar 27, 2012 6:06 am
by waligator
Hello Jonny,

In the help file:

Str1 = "ABC"
Str2 = "abc"

RetVal = Compare$(Str1, Str2, 1)

RetVal is now 0 as when case insensitive the two strings are identical.


In my example:

Test = "rec"

Return = Compare$ (Test,"REC",1)


the variable "Return" should contain "0" as in the example above.
but the variable "Return" is "1"

Simulation and real is the same

Steve

Re: Fonction "COMPARE"

Posted: Tue Mar 27, 2012 10:17 am
by JonnyW
Morning. Yes, you are right - I was thinking return '1' for match, '0' for mismatch but the function should return 0 for match.

In simulation this is because the check for the case insensitivity is missing (so checks are always case sensitive) - this will be fixed for v5.2, and apologies for this. If you wish for simulation to be OK, the only real workaround is to use the ToUpper$() and ToLower$() functions to force the case then do a case-sensitive check.

On HW, we created a simple file (attached) and this outputs as expected. It outputs '1' in simulation, but '0' on hardware, so it seems the bug is simulation only.
example_01.fcf
Simple compare
(6 KiB) Downloaded 267 times
Cheers,

Jonny

Re: Fonction "COMPARE"

Posted: Tue Mar 27, 2012 10:40 am
by waligator
Ok
Pending V5.2, I'll change my project accordingly.

thank you for your check.
Steve