Quote constant?

C

Charlotte E.

Hi,


I would like to make a vbQuote constant, like:

Const vbQuote As String = Chr(34)

....so that I can use vbQuote when I need to insert a " in a string,
instead of Chr(34).

But when I do the above code line to define the constant, I get an error
saying that a constant expression is needed.

But, in my eyes that is a constant expression???

So, how do I make a vbQuote constants?


Thanks,

CE
 
W

Walter Briscoe

In message <[email protected]> of Sat, 13
Apr 2013 09:22:32 in microsoft.public.excel.programming, Charlotte E.
Hi,


I would like to make a vbQuote constant, like:

Const vbQuote As String = Chr(34)

...so that I can use vbQuote when I need to insert a " in a string,
instead of Chr(34).

But when I do the above code line to define the constant, I get an
error saying that a constant expression is needed.

But, in my eyes that is a constant expression???

It may produce a fixed result, but that result is not, technically, a
constant.
So, how do I make a vbQuote constants?


Thanks,

CE

This:
vbQuote = ["]


is the result of running foo:

Option Explicit
Const vbQuote As String = """"

Public Sub foo()
Debug.Print "vbQuote = [" & vbQuote & "]"
End Sub
 
G

GS

I'd set this up as a global variable...

Public vbQuote$

...and initialize its value in my InitGlobals procedure at startup...

vbQuote = Chr(34)

...so in the Immediate Window, typing...

?vbquote

...returns

"

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
C

Charlotte E.

I like this one :)

Both makes the variable global, but also opens up for temporary use of
the variable for other purposes - as long as you remember to set it back :)

Thanks,

CE


Den 13.04.2013 20:18, GS skrev:
 
A

Auric__

Charlotte said:
Den 13.04.2013 20:18, GS skrev:
I like this one :)

Both makes the variable global, but also opens up for temporary use of
the variable for other purposes - as long as you remember to set it back
:)

But that defeats the whole purpose of using constants. Walter's version...

Const vbQuote As String = """"

....is what I would use.
 
G

GS

But that defeats the whole purpose of using constants. Walter's
version...

Const vbQuote As String = """"

I agree! My reply was only to suggest a way to use Chr(34), which she
stated she wanted some way to do that.

Personally, I'd just use the keyboard in most cases, but I do see a
value in storing this in a variable/constant when passing double quotes
as an arg or when filtering...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
C

CellShocked

I agree! My reply was only to suggest a way to use Chr(34), which she
stated she wanted some way to do that.

Personally, I'd just use the keyboard in most cases, but I do see a
value in storing this in a variable/constant when passing double quotes
as an arg or when filtering...


Could it have to do with touch screen interface considerations?
 
G

GS

Could it have to do with touch screen interface considerations?

Doubtful!<g>
Which is easier typing...

""""

...to get "

OR

vbQuote

...when string building needs internal quotes within the string?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top