Page 1 of 1

Compare$() does not work as advertised?

Posted: Thu Jul 29, 2010 7:24 am
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!

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

Posted: Thu Jul 29, 2010 8:34 am
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.

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

Posted: Fri Jul 30, 2010 1:52 am
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.

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

Posted: Fri Jul 30, 2010 1:54 am
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.

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

Posted: Fri Jul 30, 2010 8:30 am
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.

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

Posted: Sat Jul 31, 2010 12:57 am
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.

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

Posted: Sat Jul 31, 2010 3:36 am
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.

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

Posted: Fri Feb 28, 2020 9:19 pm
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.

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

Posted: Fri Feb 28, 2020 10:56 pm
by kersing
Are you trying to compare strings? Compare$ is for strings, not other data types.