Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default How to create module wide 'constant'?

Excel Helper

I am writing some code which consists of circa 10 different procedures
within a module.

I want to be able to refer to an array in each without having to declare it
in each module.

My array is:

ddRWS = Array(4,16,28,40,52,64,76,88,100)

I want to be able to refer to this in each procedure with statements like:

ddRWS(2)
For i = UBound(ddRWS) to UBound(ddRWS)

Can I declare this array once at the top of the module and then refer to it
during proecedures? I have already tried:

Public ddRWS as Variant
ddRWS = Array(4,16,28,40,52,64,76,88,100)

....this didn't work so i tried...

Public ddRWS as Variant
Const = Array(4,16,28,40,52,64,76,88,100)

How can I declare my array and the assocaited values once only at the module
level so that it can be referred to in subsequent procedures?

Regards


Alex
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default How to create module wide 'constant'?

You declare an array like any other variable - if you leave out the data type
it assumes it's variant, ie:

Dim ddRWS(8) As Integer

would declare an array that would work for you. At the top of the module,
this becomes an array that is shared throughout the module (you can use
Public instead of Dim if you want other modules in your project to share it
too).

You would then need to populate it from a procedure, eg:
Sub myPopulate()
ddRWS(0) = 4
ddRWS(1) = 16
etc (or more normally a loop of some kind)

Once populated, because it was declared at the module level it can be used
by any procedure in the module. However, like all variables, it will be
reset once a macro stops running.

Hope that helps

"Alex" wrote:

Excel Helper

I am writing some code which consists of circa 10 different procedures
within a module.

I want to be able to refer to an array in each without having to declare it
in each module.

My array is:

ddRWS = Array(4,16,28,40,52,64,76,88,100)

I want to be able to refer to this in each procedure with statements like:

ddRWS(2)
For i = UBound(ddRWS) to UBound(ddRWS)

Can I declare this array once at the top of the module and then refer to it
during proecedures? I have already tried:

Public ddRWS as Variant
ddRWS = Array(4,16,28,40,52,64,76,88,100)

...this didn't work so i tried...

Public ddRWS as Variant
Const = Array(4,16,28,40,52,64,76,88,100)

How can I declare my array and the assocaited values once only at the module
level so that it can be referred to in subsequent procedures?

Regards


Alex

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default How to create module wide 'constant'?

Hi Alex,

1)you can declare your array public at top of the module and then
populate it with the values in any procedure and read the values in any
procedure

2)you can use class module and property let, property get statements.

Regards,
Ivan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default How to create module wide 'constant'?

Alex,
An alternative, if you truly want a constant...
....
Public Const ddRWS As String = "4,16,28,40,52,64,76,88,100"

Sub GetSome()
Dim x As Variant
x = Split(ddRWS, ",")
MsgBox x(7)
End Sub
------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Alex"
wrote in message
Excel Helper
I am writing some code which consists of circa 10 different procedures
within a module.
I want to be able to refer to an array in each without having to declare it
in each module.
My array is:

ddRWS = Array(4,16,28,40,52,64,76,88,100)

I want to be able to refer to this in each procedure with statements like:

ddRWS(2)
For i = UBound(ddRWS) to UBound(ddRWS)

Can I declare this array once at the top of the module and then refer to it
during proecedures? I have already tried:

Public ddRWS as Variant
ddRWS = Array(4,16,28,40,52,64,76,88,100)

....this didn't work so i tried...

Public ddRWS as Variant
Const = Array(4,16,28,40,52,64,76,88,100)

How can I declare my array and the assocaited values once only at the module
level so that it can be referred to in subsequent procedures?
Regards
Alex
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a chart with wide range of numbers Roxana Charts and Charting in Excel 3 October 16th 08 04:57 PM
How do I make the 1st column constant in viewing a wide spreadshee Greg Excel Worksheet Functions 4 October 4th 06 06:28 PM
How to create a constant total column in Excel? james9662 Excel Worksheet Functions 1 April 25th 06 08:31 PM
Create an add-in from a VB module Wayne_Perth_WA Excel Programming 1 June 2nd 05 09:19 AM
Set module-wide objects? Ed Excel Programming 4 January 24th 05 08:51 PM


All times are GMT +1. The time now is 03:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"