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...
Thanks and regards,
Brendan
Error when returning a string from a macro
-
- Posts: 44
- http://meble-kuchenne.info.pl
- Joined: Tue Dec 08, 2020 2:12 pm
- Has thanked: 35 times
- Been thanked: 11 times
-
- Valued Contributor
- Posts: 1306
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 315 times
- Been thanked: 455 times
Re: Error when returning a string from a macro
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
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
Re: Error when returning a string from a macro
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
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.
-
- Matrix Staff
- Posts: 1377
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 184 times
- Been thanked: 318 times
Re: Error when returning a string from a macro
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.
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 156 times
-
- Valued Contributor
- Posts: 180
- Joined: Wed Dec 02, 2020 7:28 pm
- Has thanked: 73 times
- Been thanked: 63 times
Re: Error when returning a string from a macro
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.)
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.)
Re: Error when returning a string from a macro
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
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
Re: Error when returning a string from a macro
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.
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.
-
- Matrix Staff
- Posts: 1377
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 184 times
- Been thanked: 318 times
Re: Error when returning a string from a macro
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").
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:
If you change this to the following and then save it from the text editor, it should work ok when loaded back into Flowcode:
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='""' setinit='' >
<array size='0' />
</return>
Code: Select all
<array size='0' />
Code: Select all
<array size='2000' />