Wish for a Sub that shares it's vars with the caller

Features wanted...
Post Reply
PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Wish for a Sub that shares it's vars with the caller

Post by PeterH »

(I dare to ask. Who asks can lose, who doesn't has lost.)
(And, at chance, you just have heared what's it good for :whistle: )


Often in a script I have the need for the same logic in different places. In "general" that's where you use a function.

*But:* often this code is connected to the calling script with a *big* bunch of variables. So functions become "un-handy" here.

My wish: a kind of "sublocal" command to call a subroutine, that works in the same environment as the caller, especially regarding variables. This regards reading, setting, and optimal also creating variables.
(In other words: as if the code were just part of the calling script. And so it's meant to be.)

As all variables are shared, there's no need for parameters or return value. (If needed it can be simulated by some vars.)
For it's physical dependency it's OK to be just callable, no need to load it. I think it's even *helpful* if the code is part of the 'master' (i.e. calling) script file!

For me this would be *very* helpful, to create less redundant, smaller, and cleaner code.
Also would reduce the needed level of indentations. :tup:
OK: who uses it is responsible for what he does :ugeek:

And I have the impression that it could be of use for others, too.
(I hope some say their opinion!)

And I hope it's not too hard to realize...

admin
Site Admin
Posts: 66094
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Wish for a Sub that shares it's vars with the caller

Post by admin »

Sounds like GoSub...Return in VBA. I don't think I want to do that ATM.

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Wish for a Sub that shares it's vars with the caller

Post by PeterH »

Sad to hear, but half expected.

Don't know VBA.
In XY it's like sub, but without creating a new environment, i.e. a new level of variables. (That's why it seems so siimple...)

OK: this means a lot more work, a lot more planning, and maybe in the end let plans be too diffiicult. I'll see.

Have a nice (and hot) day!

Post Reply