Page 1 of 1

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

Posted: 16 Jun 2023 12:52
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...

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

Posted: 17 Jun 2023 08:56
by admin
Sounds like GoSub...Return in VBA. I don't think I want to do that ATM.

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

Posted: 17 Jun 2023 12:55
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!