[Solved] Macro return string longer than 20 characters

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times

[Solved] Macro return string longer than 20 characters

Post by tiny »

Is it possible to set a return string of a macro longer than 20 characters?
I am using Flowcode 7, latest version.
Example: Search and Replace a Character in a String. I would like to use this function with some other string manipulations in a component macro.
If I now want to edit strings longer 20 characters with a component macro is not possible.

Thanks
Christina
Last edited by tiny on Thu Aug 17, 2017 11:49 am, edited 1 time in total.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: Macro return string longer than 20 characters

Post by LeighM »

Hi Christina,
You could pass the source string as a parameter into the editing macro.
In the string parameter details, just make sure that the "Make a local copy of the value" is not ticked.
You can then make changes to the string in the macro, no need to return it.
Hope that helps,
Leigh

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times

Re: Macro return string longer than 20 characters

Post by Docara »

HI Tiny,

Just guessing - Could the problem be that FC defaults the string length to 20 characters

After you have setup the string variable go back into it and click on the 20 in the square brackets and change it . I found a similar problem which compiled and simulated correctly but failed in hardware and this was the cause.

Matt

User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times

Re: Macro return string longer than 20 characters

Post by tiny »

Thanks for the quick reply!
Could you please show me how this works with parameter transfer? I have simple tools, which I always need again, packed into a component macro. Attached is a small example with the Replace function, but only works with short strings.

Thanks
Christina
StringTools.fcfx
(11.91 KiB) Downloaded 300 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: Macro return string longer than 20 characters

Post by LeighM »

Hi Christina,

Sorry, it looks like we have a bug.
The limiting to 20 characters is being done at the point where the string is returned from the Replace macro.
This is happening for simulation, but looks like it should be OK for downloaded target code.

A workaround for this problem would be to have the Replace macro work on the original string.
To do that, the string parameter needs the "Make a local copy of the value" to be un-ticked.
string_copy.jpg
string_copy.jpg (57.37 KiB) Viewed 7070 times
In order to debug this issue I simplified the Replace macro, which might be of value to you, so I have attached my version.
If you run this simulation, with the box ticked and un-ticked and compare what happens with the "test" and "result" strings you will see the issue.

Regards,
Leigh
Attachments
StringTools2.fcfx
(13.07 KiB) Downloaded 250 times

User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times

Re: Macro return string longer than 20 characters

Post by tiny »

Thank you, now I understand it! I have created an additional input, declare it as not a local copy, and pass the result at the end of this input string. This keeps the original string unchanged and it also works with the simulation.

Christina

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: [Solved] Macro return string longer than 20 characters

Post by LeighM »

Sounds good :D

streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times

Re: [Not Solved] Macro return string longer than 20 characte

Post by streammaster »

Hi Leigh,

I followed the example which you provided (which is not working on my Flowcode 7: the result is only 20 characters regardless ticked box as you suggested in workaround bellow.
The Flowcode which i'm running is a pro version V7.2.14 (Mar 31 2017)
I also tried to make a test application to further simplified it.
String test.fcfx
(8.19 KiB) Downloaded 240 times
Could you please help me with resolving this bug? At this stage i'm trying the simulation only.

Regards,
Igor

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: [Solved] Macro return string longer than 20 characters

Post by LeighM »

Hi Igor,

Try the attached, which has the work around suggested by tiny.

Regards,
Leigh
Attachments
String test 2.fcfx
(8.64 KiB) Downloaded 252 times

streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times

Re: [Solved] Macro return string longer than 20 characters

Post by streammaster »

Thanks for this, but this is using a global variable. Unfortunately this is stopping of using the function call like this (which can be called also by interrupt)::

s_processed = some_other_string_variable + Process_my_text ("input string") +"some other string"

If i have a interrupt calls i'm not sure if the global variable would have return content of actual loop or, or by process called by interrupt? Apart having different global for each (same) function segment call what would make whole thing not efficient with so many declared (and reserved) variables. Is there any way that you can do to fix the 20 character limitation and have actual component how suppose to be? Either allow to be defined in return declaration like Return[50] or so it inherit the property of local string variable:

.local_return[50]
Return=.local_return

Regards,
Igor

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: [Solved] Macro return string longer than 20 characters

Post by LeighM »

Hi,
Yes, you are right, it's a bug that needs fixing.
Although string concatenation does have a few other quirks, so it is best to do things in steps.
Also the output variable does not have to be global.
So you could try something like this...

Code: Select all

s_processed = some_other_string_variable
Process_my_text ("input string", s_processed ) 
s_processed =  s_processed + "some other string"

Post Reply