experchange > vb.* > vb.general.discussion

Stan Weiss (07-08-19, 10:19 AM)
Is there a way to pass the name of a Sub Routine to a sub routine as a
parameter In its simplest form.

Sub Test(Sub_Name As Sub)

Call Sub_Name

End Sub

Stan
Arne Saknussemm (07-08-19, 10:53 AM)
:: On Mon, 8 Jul 2019 04:19:04 -0400
:: (microsoft.public.vb.general.discussion)
:: <qfuu9n$1nje$1>
:: Stan Weiss <srweiss> wrote:

> Is there a way to pass the name of a Sub Routine to a sub routine as
> a parameter In its simplest form.
> Sub Test(Sub_Name As Sub)
> Call Sub_Name
> End Sub


Check these



Stan Weiss (07-08-19, 03:56 PM)
On 7/8/2019 4:53 AM, Arne Saknussemm wrote:
> :: On Mon, 8 Jul 2019 04:19:04 -0400
> :: (microsoft.public.vb.general.discussion)
> :: <qfuu9nnje>
> :: Stan Weiss <srweiss> wrote:
> Check these
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> Arne,


Thanks that works if the sub routine is in that form. But each of the
sub routines (8 at this time) that I want to use are each in their own
module.  Is there a way to make that work?

Thanks,

Stan
GS (07-08-19, 08:51 PM)
> On 7/8/2019 4:53 AM, Arne Saknussemm wrote:
> Arne,
> Thanks that works if the sub routine is in that form. But each of the sub
> routines (8 at this time) that I want to use are each in their own module.
> Is there a way to make that work?
> Thanks,
> Stan


It doesn't matter if the sub routines are in different modules so long as they
aren't scoped as Private.
Stan Weiss (07-08-19, 09:13 PM)
On 7/8/2019 2:51 PM, GS wrote:
> It doesn't matter if the sub routines are in different modules so long
> as they aren't scoped as Private. Garry,


They are Public. I changed a couple of the modules to forms and added a
parameter to pass the form name and it is working.

Private Sub Do_Calc(MyForm As Form, ByVal sub_name As String) '6.1.5

code

CallByName MyForm, sub_name, VbMethod

Thanks,

Stan
Arne Saknussemm (07-09-19, 11:41 AM)
:: On Mon, 8 Jul 2019 15:13:29 -0400
:: (microsoft.public.vb.general.discussion)
:: <qg04kn$19vh$1>
:: Stan Weiss <srweiss> wrote:

> CallByName MyForm, sub_name, VbMethod


notice that you may pass parameters to the methods by using a variant
array, here's a quick example

CallByName Me, SomeSub, vbMethod, Array(1, "aa", 45.57)

HTH
Arne Saknussemm (07-09-19, 11:42 AM)
:: On Tue, 9 Jul 2019 11:41:27 +0200
:: (microsoft.public.vb.general.discussion)
:: <20190709114127.00007869>
:: Arne Saknussemm <idm.10.arnsak> wrote:

> :: On Mon, 8 Jul 2019 15:13:29 -0400
> :: (microsoft.public.vb.general.discussion)
> :: <qg04knvh>
> :: Stan Weiss <srweiss> wrote:
> notice that you may pass parameters to the methods by using a variant
> array, here's a quick example
> CallByName Me, SomeSub, vbMethod, Array(1, "aa", 45.57)


forgot, the call also works if the methods are inside a class module,
so you may change your modules to class modules, instance the classes
and then use them to issue the calls
Arne Saknussemm (07-09-19, 04:09 PM)
:: On Tue, 9 Jul 2019 11:42:56 +0200
:: (microsoft.public.vb.general.discussion)
:: <20190709114256.00003188>
:: Arne Saknussemm <idm.10.arnsak> wrote:

> forgot, the call also works if the methods are inside a class module


All in all, a Form is just a class module with a graphical interface :)
so if you don't need the interface, just use a class, spare resources
and obtain the same result :)