Declare Const with a string (1 Viewer)

Jayce72

Registered User.
Local time
Today, 16:41
Joined
Sep 26, 2011
Messages
60
Hi

Im trying to declare a const

I have declared

Dim strPRX as string.
strPRX = "Test"

Im using:
Const spath = "C:\Users\Jim" & strPRX & ""

I Get:
spath = C:\Users\Jim\& strPRX &\

What Im trying to achieve is that spath = C:\Users\Jim\Test\

Any help please
 

moke123

AWF VIP
Local time
Today, 11:41
Joined
Jan 11, 2013
Messages
3,933
try
Code:
Const spath = "C:\Users\Jim\" & strPRX & "\"
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:41
Joined
Feb 19, 2013
Messages
16,638
have you posted what you are doing correctly? VBA doesn't create characters out of thin air

there is no way

Im using:
Const spath = "C:\Users\Jim" & strPRX & ""

will add the additional \ characters

spath = C:\Users\Jim\& strPRX &\
 

Jayce72

Registered User.
Local time
Today, 16:41
Joined
Sep 26, 2011
Messages
60
have you posted what you are doing correctly? VBA doesn't create characters out of thin air

there is no way

Im using:
Const spath = "C:\Users\Jim" & strPRX & ""

will add the additional \ characters

spath = C:\Users\Jim\& strPRX &\

Hi - thanks - I've messed around with this so much I might have written it incorrectly.

I have a path that is always: C:\Users\Jim\
I then create a new folder called Test

I am then trying to get: const spath = "string etc"

to say : C:\Users\Jim\Test\
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:41
Joined
Feb 19, 2013
Messages
16,638
by its definition, a constant is a constant - you cannot assign a variable to it. So strPRX also needs to be a constant.

Alternatively, change spath from const to dim
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:41
Joined
Feb 28, 2001
Messages
27,249
To amplify what CJ is saying, the only way to get spath to be combined from two strings is to define it originally that way as a constant, and constants must be defined in a declaration section, not in executable code.

If you change from Const to Dim, it becomes an ordinary variable for which values can be assigned dynamically.
 

Users who are viewing this thread

Top Bottom