How to make a public routine for all forms without being tied to a form?

Asked

Viewed 443 times

0

I have several forms in my application, and I can start the call by some of them running partial for testing (not necessarily START from the main form).

In addition to the public variables that are in a module, I tried to do the same with public routines and functions, so that they were not spread in codes of several forms or concentrated in one, because in either case the partial call of the application would not load all functions and routines that could be requested.

You can do it?

For example, I want a public routine that puts the "default" values in public variables, but not in a form code.

     Public Sub InicializaVariaveisPublicas()

     VersaoATual = "2.03.017"

     QuantidadeMaximaProjetos = 2

     QuantidadeMaximaItens = 10

     ArrastoMouse = False

     MaximoTentativas = 3

     ...

     ...

     End Sub

HICCUP

See answer below

  • What went wrong when you put her in the module? That’s how you do it.

  • Syntax error occurs when calling the routine, I checked name, parameters, but found nothing. I will try again

  • A question, I call one of the public routines as the first command of a Form, ie in Form_activate. This may be the error?

  • Put in the answer as it gets inside the module, with the signature of the whole module and as you are calling the function, test call the function in a click and not active too

  • Ricardo, the mistake was that I was calling the routine with parentheses to put two arguments, Rotina(a,b), just take them off and it worked, even if it was the first call from Ctivate. Routine a,b I will put in question. Grateful

  • 1

    In VB subs vc calls without () and functions with ()

  • Okay, it was distraction, because before I had done as a function and then changed to routine without having tested. Thanks!

  • Create an answer to your question, in which case you answer and accept the answer yourself. Abs

  • 1

    @Leo see here a short explanation of how the parentheses work.

  • Okay, that’s exactly what happened... thanks

Show 5 more comments

1 answer

1


ERROR FOUND

The error was by distraction, I was calling the routine with parentheses to put two arguments: Routine(a, b), Just take them out and it worked, even being the first call of Form_activate, Routine a, b.

Therefore, just do the routines and public functions in a single "module" that works.

In my case I have three modules, one for public variables, one for public routines and functions and one for Excel macros.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.