Compare$() does not work as advertised?

Forum for problems or queries regarding the Flowcode application and compiler usage.

Moderators: Benj, Mods

Post Reply
TomB12
Posts: 4
Joined: Sun Jul 25, 2010 1:43 am

Compare$() does not work as advertised?

Post by TomB12 »

In Flowcode, I am using the 16F88 with the kit. When I run a special program I wrote the compare$() function gave a '0' when the strings were the same length, but not when they were identical. If anyone wants to see the code I can upload the .fcf and you can verify it for yourself. I am attending DeVry University and they only provide v3.0 of Flowcode. Is there a command that will compare the two strings byte-by-byte, or, do I have to have a function to the compare a byte at a time?
Thank you!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Compare$() does not work as advertised?

Post by Benj »

Hello,

Flowcode v3.0 is very old now (Nearly 4 years) and we highly recommend updating to Flowcode v3.7 or even v4.3 though this will incurr an upgrade charge.

Please can you attach a simple fcf file that shows the problem along with the C code file that is generated upon compilation.

TomB12
Posts: 4
Joined: Sun Jul 25, 2010 1:43 am

Re: Compare$() does not work as advertised?

Post by TomB12 »

I have to use what the university loads on their laptop, unfortunately. v 3.4.7.48 is the version they provide. Upgrading regardless of cost is not an option. Attached is the .fcf file. I will upload the .c file shortly.
Attachments
Test_Compare.fcf
(11.75 KiB) Downloaded 690 times

TomB12
Posts: 4
Joined: Sun Jul 25, 2010 1:43 am

Re: Compare$() does not work as advertised?

Post by TomB12 »

Attached is the .c file for my brief test program.
This program merely compares different strings several times and gives the results, match or not match.
Attachments
Test_Compare.c
(12.86 KiB) Downloaded 565 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Compare$() does not work as advertised?

Post by Benj »

Hello,

One thing I noticed from looking at your program is that you are loading the compare function with two strings and the length of the string.

The third parameter should not be the string length and instead represents whether to try and match case or not.

0 - case sensitive
1 - case insensitive

If you are loading this parameter with a value more then 1 then you may get unexpected results.

TomB12
Posts: 4
Joined: Sun Jul 25, 2010 1:43 am

Re: Compare$() does not work as advertised?

Post by TomB12 »

Okay, I did manage to find what you are talking about in the Help. I did not find it in the string description online, which I did not expect. I have made some changes to the test program and have discovered that the numeric strings are not compared, but the character strings are. I put my latest test, .fcf and .c, into a zip file, attached.
I find it rather disturbing that all the numeric string passed without a problem, regardless of case, while the alpha characters did not pass if the letters differed or were the wrong case. As a backstop I did a test of a string to itself to verify.
Should the Compare$ function be comparing alpha characters and not numbers?
Of course, if numbers are included in an alpha string, then the difference is noted if the numbers are different from one string to another.
Attachments
Test_Compare.zip
This .zip file contains both the .fcf and .c files.
(6.47 KiB) Downloaded 628 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Compare$() does not work as advertised?

Post by medelec35 »

Hello TomB12
You had two types of problems with your flowchart which I have corrected for you.
1) You are using format: length = Length$(first_string)
comp = Compare$(first_string, third_string, length)
If you look at the help within Flowcode you will see the following:

Code: Select all

Compare$(string1, string2, compare_type) 
Compares the two strings, parameters 1 and 2, and returns a BYTE value corresponding to the following results:

	0 = strings are identical
	1 = string1>string2
	255 = string2>string1

The 3rd parameter, compare_type,  determines whether or not the check is case sensitive. values for compare_type are:

0 = case sensitive
	1 = case insensitive.
Examples

Str1 = "ABC"
Str2 = "abc"

So as both help and Ben shows the third parameter is Case and not length. So if case sensitive you should have:
comp = Compare$(first_string, third_string, 0)
If not case sensitive you should have:
comp = Compare$(first_string, third_string, 1)

The final issue you said does not compared Numeric strings. This was down to wrong coding of decision branch.
E.g. for test 2 you had:
If comp = 1 then Call print Not Okay macro.
If comp = any other number then Call print Okay macro.

Since string two is greater than string one the result is 255. You have not got an option to capture 255, only 1.
Since 255 is not = 1 then Call print Okay macro was accessed.
So the solution is use same decision as in test 1. I.e :
If comp = 0 then Call print Okay macro.
If comp = any other number Call print Not Okay macro.

I have also corrected the formatting of print Okay macro. E.g did not look right if first string matched, second string did not match and third string matched.
Hope this helps.
Attachments
Test_Compare for V3_corrected.fcf
(12.05 KiB) Downloaded 671 times
Martin

Leomar
Posts: 3
Joined: Fri Feb 28, 2020 9:01 pm
Has thanked: 1 time

Re: Compare$() does not work as advertised?

Post by Leomar »

Hello everyone.

I have a comparison problem.


I need to create a vector inside the flowcode, to read the analog input, read 200 times.

These readings must be saved in a vector.

After comparing to see which is the highest value.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: Compare$() does not work as advertised?

Post by kersing »

Are you trying to compare strings? Compare$ is for strings, not other data types.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply