global vars (esp. array)

codesmith

Active Member
Joined
Apr 23, 2008
Messages
257
Hey all ... wanting to know how I can define a global array such that any of my sub routines or functions can view/edit it?

Thanks in advance.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
For variables in the same project (Excel file with all the modules, worksheets, userforms), you just basically declare the variable as a public variable in a standard module, which means at the top before any subs or functions and with the keyword Public:

Code:
Public gstrMyName as String

Sub UseIt()
Msgbox gstrMyName
End Sub

I use prefix conventions for public and private variables (variables with scope outside the current procedure):

g for global variable - project level scope
p for private variables - module level scope

Followed of course by the datatype:
i.e.
pintNumber = a private integer,
gblnTrueOrFalse = a public boolean,
plngCount = a private long,
etc. etc.


I guess for reasons I don't understand I usually don't use prefixes for arrays, but if I did I think I'd use arr, I.e. arrMyArray or garrMyArray / parrMyArray - I suppose its in the nature of array variables that they are easily recognized by the manner of their use...

AB
HTH
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,568
Messages
6,125,599
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top