String constants in Declaration section?

String constants in Declaration section?

Anonymous
Not applicable
169 Views
4 Replies
Message 1 of 5

String constants in Declaration section?

Anonymous
Not applicable
When trying to issue this command in the Declarations section of my
UserForm:

Public Const BLOCK_DIR="C:\Blocks"

I get this error:

Constants, fixed-length strings, arrays, and Declare statements not
allowed as Public members of an object module.

Why in the world can you not define a Public String Constant? and what is
the correct way to achieve this most logical approach I have tried.
0 Likes
170 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Hi Matt,

I think you have to put your declaration in a module, not on a form.

Regards,

Arno van Eeuwen

Matt Slay wrote:

> When trying to issue this command in the Declarations section of my
> UserForm:
>
> Public Const BLOCK_DIR="C:\Blocks"
>
> I get this error:
>
> Constants, fixed-length strings, arrays, and Declare statements not
> allowed as Public members of an object module.
>
> Why in the world can you not define a Public String Constant? and what is
> the correct way to achieve this most logical approach I have tried.
0 Likes
Message 3 of 5

Anonymous
Not applicable
The "correct" way is to expose your string constant via a property (yes,
forms can have them, too):

Public Property Get BlockDir() as String
BlockDir = BLOCK_DIR
End Property

I'll leave the "why" to someone else. 🙂

Mark Holder

Matt Slay wrote:

> When trying to issue this command in the Declarations section of my
> UserForm:
>
> Public Const BLOCK_DIR="C:\Blocks"
>
> I get this error:
>
> Constants, fixed-length strings, arrays, and Declare statements not
> allowed as Public members of an object module.
>
> Why in the world can you not define a Public String Constant? and what is
> the correct way to achieve this most logical approach I have tried.
0 Likes
Message 4 of 5

Anonymous
Not applicable
Thanks Mark,

Very interesting remark.

Arno

Mark Holder wrote:

> The "correct" way is to expose your string constant via a property (yes,
> forms can have them, too):
>
> Public Property Get BlockDir() as String
> BlockDir = BLOCK_DIR
> End Property
>
> I'll leave the "why" to someone else. 🙂
>
> Mark Holder
>
> Matt Slay wrote:
>
> > When trying to issue this command in the Declarations section of my
> > UserForm:
> >
> > Public Const BLOCK_DIR="C:\Blocks"
> >
> > I get this error:
> >
> > Constants, fixed-length strings, arrays, and Declare statements not
> > allowed as Public members of an object module.
> >
> > Why in the world can you not define a Public String Constant? and what is
> > the correct way to achieve this most logical approach I have tried.
0 Likes
Message 5 of 5

Anonymous
Not applicable
Arno:
Yes, it can be at all modules and form as long as it is in the declare
section.
Ken
Arno <106154.2325@compuserve.com> wrote in message
news:381CACFE.48D923CB@compuserve.com...
> Hi Matt,
>
> I think you have to put your declaration in a module, not on a form.
>
> Regards,
>
> Arno van Eeuwen
>
>
>
> Matt Slay wrote:
>
> > When trying to issue this command in the Declarations section of my
> > UserForm:
> >
> > Public Const BLOCK_DIR="C:\Blocks"
> >
> > I get this error:
> >
> > Constants, fixed-length strings, arrays, and Declare statements not
> > allowed as Public members of an object module.
> >
> > Why in the world can you not define a Public String Constant? and what
is
> > the correct way to achieve this most logical approach I have tried.
>
>
>
0 Likes