Error when returning a string from a macro

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
Brendan
Posts: 43
http://meble-kuchenne.info.pl
Joined: Tue Dec 08, 2020 2:12 pm
Has thanked: 35 times
Been thanked: 10 times

Flowcode v10 Error when returning a string from a macro

Post by Brendan »

I tried to return a short string compiled inside a macro.

The .return type parameter was appropriately declared as 'string'.

However, when I try to copy the compiled string to .return in a calculation, the following results...

FC_Returning_String_Error.png
FC_Returning_String_Error.png (70.51 KiB) Viewed 684 times


Thanks and regards,

Brendan

chipfryer27
Valued Contributor
Posts: 1145
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 282 times
Been thanked: 412 times

Re: Error when returning a string from a macro

Post by chipfryer27 »

Hi

I would need to see your chart to be sure but it looks like you are trying to do a type conversion within a calculation.

Unless both variables are of the same type you cannot just use the equals (=) to assign values.

In your screenshot, it looks like you are trying to assign the value of local variable Result_String to local variable Return but I don't see Return listed as a local variable so I don't know if this is a string value or not. If it isn't a string value and you wish to assign a string to it you will need to use one of the F$ built in functions in your calculation such as x = StringToInt$(y_String) if for example x was an integer.

Hope this helps

Regards

Brendan
Posts: 43
Joined: Tue Dec 08, 2020 2:12 pm
Has thanked: 35 times
Been thanked: 10 times

Re: Error when returning a string from a macro

Post by Brendan »

Thanks Chip...

The .return is declared within the macro editing pane, the var type set when creating the macro (i.e. drop-down at the bottom of the macro edit pane), and the name .return is therefore reserved for this purpose and data type already declared.

Various data types are available and, as you rightly point out, data types must match.

I've used this feature many times - typically with integer variables to pass back error codes (etc) without issue, so that when the macro is called by the main thread, an external variable is then able to collect and process the value passed out via .return.

One of the options for .return data type in the drop-down is 'string', but FC complains (per pictorial) when passing string data (from within the macro) to .return declared as 'string'.

The workaround would be to directly update a global variable from within the macro, though I'm highlighting this bug as a feature that evidently has an issue with strings, and useful if macros are reused between projects when the external var name (collecting returned data) isn't known. Such examples feature in many Flowcode components.

All the best,
Brendan
Last edited by Brendan on Wed Jan 31, 2024 10:29 am, edited 1 time in total.

Steve-Matrix
Matrix Staff
Posts: 1249
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: Error when returning a string from a macro

Post by Steve-Matrix »

I've checked and this is working fine for me (see attached).

If you're still having this problem, please post your project file and I will investigate.
Attachments
string return from macro.fcfx
(8.34 KiB) Downloaded 37 times

kersing
Valued Contributor
Posts: 157
Joined: Wed Dec 02, 2020 7:28 pm
Has thanked: 64 times
Been thanked: 58 times

Re: Error when returning a string from a macro

Post by kersing »

Hi Brendan,

Did you by any chance change the return type of the macro? If I recall correctly I had some issues when I did that recently. I had to recreate the macro with the correct type and copy the code to that new macro to resolve that. (Reloading the project and even restarting Flowcode didn’t solve it.)

Brendan
Posts: 43
Joined: Tue Dec 08, 2020 2:12 pm
Has thanked: 35 times
Been thanked: 10 times

Re: Error when returning a string from a macro

Post by Brendan »

Thank you Steve and Kersing.

Kersing's suggestion could indeed work, as originally .return was declared as integer until changed and macro code modified to pass back a string.

Will update once tried and tested against your suggestions :)

Many thanks!
Brendan

Brendan
Posts: 43
Joined: Tue Dec 08, 2020 2:12 pm
Has thanked: 35 times
Been thanked: 10 times

Re: Error when returning a string from a macro

Post by Brendan »

UPDATE...

I can confirm the following, per Kersing's experience and advice:

1. I created a new macro, setting the .return type to 'string' immediately on creation, and with added local vars the same as the problem macro.

2. Copy-pasted the flow from the problem macro to new macro.

3. Removed all calls to the problem macro and deleted it.

4. Renamed the new macro as the old/deleted macro.

5. Closed/restarted Flowcode and and re-opened the project.

I am now able to successfully copy strings to .return without operand error, so thank you Kersing for sharing your valuable observations and workaround :)

Although I haven't explored any further at this stage, I suspect that if wishing to copy strings to .return then it may first be necessary to define .return as a string immediately on macro creation to avoid throwing up this issue.

Thank you everyone for your most valued advice and support.

Brendan.

Steve-Matrix
Matrix Staff
Posts: 1249
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: Error when returning a string from a macro

Post by Steve-Matrix »

Thanks Kersing and Brendan. That bug is on our list to fix.

There is a simple workaround if you find yourself in this situation. It involves editing the FCFX or FCSX project file in a text editor, so you may not want to do that. If you do edit it, make sure you create a backup first just in case.

In that file, you can find your macro by searching for its name. You should find a section that begins with the following (assuming your macro is called "NewMacro").

Code: Select all

<flowline name='NewMacro' description='' statediag='0' >
	<return name='Return' type='T8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
		<array size='0' />
	</return>
There may also be some parameters of local variables defined here. The section you need to change is the line after "<return" - i.e. this one:

Code: Select all

<array size='0' />
If you change this to the following and then save it from the text editor, it should work ok when loaded back into Flowcode:

Code: Select all

<array size='2000' />

Post Reply