Passing back parameters from sub to calling script

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Massi
Newbie
Posts: 6
Joined: Fri Jan 10, 2020 9:05 pm

Passing back parameters from sub to calling script

Post by Massi » Fri Jan 10, 2020 9:52 pm

Hello,
I am a new user of MS since 3 weeks only and this is my first post to this forum.
I have already experimented quite a lot and already produced running EXE in this short time.
However, for sure, I have still a lot to learn about MS.

Variable localization nesting effect of it and parameter passing to a Sub are clear concepts for me.
I do not like utilization of global variables if not strictly necessary.
I have also understood that it is possible to write VBA code in MS to exploit functions and pass ByRef or return variables via functions in VBA style.

My Question:
Can you recommend me the best, efficient and elegant way to create a function like code in MS to return back parameters to the caller code without using global variables?
- Please to make me a simple example
- I would like to know also how to return back arrays and complex data.

Before starting to use intensively MS I would like to clarify this point.

Massimo

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Passing back parameters from sub to calling script

Post by Marcus Tettmar » Tue Jan 21, 2020 4:27 pm

Hi,

Subroutines do not return values. So you would need to use global variables. I would advise creating variables that have the subroutine name as a prefix to avoid confusion.

Note that in other programming languages subroutines don't return values either. Functions do. Subroutines do not. At present Macro Scheduler doesn't have native functions, just subroutines.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Massi
Newbie
Posts: 6
Joined: Fri Jan 10, 2020 9:05 pm

Re: Passing back parameters from sub to calling script

Post by Massi » Tue Jan 21, 2020 8:45 pm

Thanks.
In the meantime I have used this method.
Good idea to exploit name of variable like the Sub Name :-)

I hope that it is in your plans to extend MS to functions.

Anyway, very nice tool.
Massi

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Passing back parameters from sub to calling script

Post by PepsiHog » Sun Jan 26, 2020 4:07 pm

@Marcus,
At present Macro Scheduler doesn't have native functions, just subroutines.
Great idea! Is this in your to-do list? It should be. At the top, preferably.

I mean, I'm just saying that's like the best idea in the last 5 minutes.

Which raises the question, when do you think v15 might hit the market?

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts