Constant

W

Warrio

Hello!

Is it possible to have the value of constants, which are declared in anther
module, without having to use a Get ConstantName function for each constant?

Thanks for any suggestion
 
J

Jake Marx

Hi Warrio,

If you declare your constants like this:

Public Const gsAPP_NAME As String = "My Application"

your constant will be available to all other modules/forms. They must be
declared outside of any procedures (Subs/Functions) in a Standard Module -
typically, you'd put them at the top of the module.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
T

Tom Ogilvy

Just to add - the module has to be in the same workbook as the module code
that is trying to access the value.
--
Regards,
Tom Ogilvy

Jake Marx said:
Hi Warrio,

If you declare your constants like this:

Public Const gsAPP_NAME As String = "My Application"

your constant will be available to all other modules/forms. They must be
declared outside of any procedures (Subs/Functions) in a Standard Module -
typically, you'd put them at the top of the module.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Hello!

Is it possible to have the value of constants, which are declared in
anther module, without having to use a Get ConstantName function for
each constant?

Thanks for any suggestion
 
W

Warrio

this is what I wrote:
Public Const c_Cash_Début as Integer= 2

and I got a compilation error :
Constants, fixed-length strings, arrays, user-defined types, and Declare
statements not allowed as Public members of an object module



Jake Marx said:
Hi Warrio,

If you declare your constants like this:

Public Const gsAPP_NAME As String = "My Application"

your constant will be available to all other modules/forms. They must be
declared outside of any procedures (Subs/Functions) in a Standard Module -
typically, you'd put them at the top of the module.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Hello!

Is it possible to have the value of constants, which are declared in
anther module, without having to use a Get ConstantName function for
each constant?

Thanks for any suggestion
 
C

Chip Pearson

You can't put public constant in class modules, which include class modules,
the ThisWorkbook module, form modules and sheet modules. Declare your
constant in a regular code module, and set a reference to that project in
the project in which you want to use the constant.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com [email protected]

Warrio said:
this is what I wrote:
Public Const c_Cash_Début as Integer= 2

and I got a compilation error :
Constants, fixed-length strings, arrays, user-defined types, and Declare
statements not allowed as Public members of an object module



Jake Marx said:
Hi Warrio,

If you declare your constants like this:

Public Const gsAPP_NAME As String = "My Application"

your constant will be available to all other modules/forms. They must be
declared outside of any procedures (Subs/Functions) in a Standard Module -
typically, you'd put them at the top of the module.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Hello!

Is it possible to have the value of constants, which are declared in
anther module, without having to use a Get ConstantName function for
each constant?

Thanks for any suggestion
 
J

Jake Marx

Hi Warrio,

Public constants must be declared in Standard Modules, which doesn't include
Userforms. You could either use a Public Property or Public variable on the
UserForm, and then you could access the value with
<UserformName>.PropertyOrVarName.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

this is what I wrote:
Public Const c_Cash_Début as Integer= 2

and I got a compilation error :
Constants, fixed-length strings, arrays, user-defined types, and
Declare statements not allowed as Public members of an object module



Jake Marx said:
Hi Warrio,

If you declare your constants like this:

Public Const gsAPP_NAME As String = "My Application"

your constant will be available to all other modules/forms. They
must be declared outside of any procedures (Subs/Functions) in a
Standard Module - typically, you'd put them at the top of the module.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Hello!

Is it possible to have the value of constants, which are declared in
anther module, without having to use a Get ConstantName function for
each constant?

Thanks for any suggestion
 
W

Warrio

That's exactly what I wanted to do!!
Thanks!

Jake Marx said:
Hi Warrio,

Public constants must be declared in Standard Modules, which doesn't include
Userforms. You could either use a Public Property or Public variable on the
UserForm, and then you could access the value with
<UserformName>.PropertyOrVarName.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

this is what I wrote:
Public Const c_Cash_Début as Integer= 2

and I got a compilation error :
Constants, fixed-length strings, arrays, user-defined types, and
Declare statements not allowed as Public members of an object module



Jake Marx said:
Hi Warrio,

If you declare your constants like this:

Public Const gsAPP_NAME As String = "My Application"

your constant will be available to all other modules/forms. They
must be declared outside of any procedures (Subs/Functions) in a
Standard Module - typically, you'd put them at the top of the module.

--
Regards,

Jake Marx
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Warrio wrote:
Hello!

Is it possible to have the value of constants, which are declared in
anther module, without having to use a Get ConstantName function for
each constant?

Thanks for any suggestion
 
Top