PDA

View Full Version : Solved: How to declare public variables?



jungix
09-12-2006, 10:33 AM
HI,

just a simple question. I have a module which works perfectly. However I would like to split it into several modules that I would call in turn. Like


Public Sub Main ()

dim a As
Dim b As
Dim c As
...

Call Update
Call Sort
Call Cleaning


the other modules would use a, b and c, and might modify them (in which case the next routine must use the modified value).
I need global variables for all my main. I only want to split my code to make it more readable and easier to modify it afterwards.

Is this possible?

MWE
09-12-2006, 10:52 AM
HI,

just a simple question. I have a module which works perfectly. However I would like to split it into several modules that I would call in turn. Like


Public Sub Main ()

dim a As
Dim b As
Dim c As
...

Call Update
Call Sort
Call Cleaning

the other modules would use a, b and c, and might modify them (in which case the next routine must use the modified value).
I need global variables for all my main. I only want to split my code to make it more readable and easier to modify it afterwards.

Is this possible?
if I understand your question correctly, you wish to share certain variables among multiple procedures. You can declare the variables as Global before the first procedure in a given code module. Every procedure in the module can then use those variables.

Bob Phillips
09-12-2006, 10:58 AM
Option Explicit

Public a As
Public b As
Public c As

Public Sub Main()
...

Call Update
Call Sort
Call Cleaning

jungix
09-12-2006, 11:01 AM
Thank you!