Returning Subroutine definitions from a Macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-05
01:45 PM
- last edited on
2021-09-14
09:02 AM
by
Noemi Balogh
Is it possible to return subroutines defined in a macro? If so, how are they returned and how are they used in the caller object? Subs should be after END, and if a macro returns it, it would be before END, so I'm not sure how (if at all) this thing would work. But I really need this as I need to use certain subs repeatedly in several objects.
Thanks.
- Labels:
-
Library (GDL)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-05 02:00 PM
IF numberRequest=1 THEN GOSUB 'SubRoutine 1'
IF numberRequest=2 THEN GOSUB 'SubRoutine 2'
IF numberRequest=3 THEN GOSUB 'SubRoutine 3'
When you call your macro, write:
CALL 'Subroutine Macro' PARAMETERS numberRequest=1
CALL 'Subroutine Macro' PARAMETERS numberRequest=2
CALL 'Subroutine Macro' PARAMETERS numberRequest=3
This way you can call the same macro but in each case different subroutine. The END at the end of the script, but before subroutines scripts, does not interfere with macro call, because at the point of end script is stopping and subroutine requests and executions happen before script ends.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-05 02:19 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-05 02:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-05 03:07 PM
The caller obj calls a macro in Parameters script passing an int value, and the macro then derives the name of the sub to call (apart from other things), and returns it to the caller obj. The caller obj then calls another macro (from 2D script) containing the subs to generate 2D symbols, passing the name of the sub, pen, etc.
If the subs were in the caller obj, they updated in the 2D preview of the Obj Settings dialog.
That's the scenario roughly..
I might be having the sequence to the CALLs wrong..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-05 03:36 PM
Nevermind, it works.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-05 03:57 PM
In all these cases it’s necessary to understand what script exactly doing in this moment of time and if logically looks, that it cannot perform some operation with additional input - add some button that can help to resolve it. It’s same logic like with editing curtain wall. Exists ‘edit’ button you need to hit to enable additional function.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-06 10:04 AM
You might pass around a label of a subroutine as a string or int, but the one in the code that uses gosub/goto will be used, not the macro's that returned it.
There are two ways to solve this:
- have a subroutine collection in a macro, all their inputs as parameters plus a parameter telling which subroutine to use, and the results returned with the end command. Call the macro instead of the subroutine.
- write each subroutine in a separate macro, they can be called using a string variable for the name
Software Engineer, Library
Graphisoft SE, Budapest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-06 10:10 AM