954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Escape Sequences or Accepting Double Quotes in String Constants

Hi, I'm doing some work for an Access Database but I caught a snag writing an event. I want the event to (among other things) change the Control Source of an object. This is no problem, except I have to set the control source as a string, and the string being an Immediate if function contains a string in it.

Now in C and C++, to write double quotes in a literal constant you just use a backslash infront of it to take it as it is. Such as:

str1 = "President Lincoln said \"Four score and seven years ago...\""


I tried this in my VBA statement and no such luck. It just took the backslash in a string and closed the string at the quotes, like so:

[foo].ControlSource = "=IIf([foo]>0, 100*([foo1]/[foo2]) & \"%\", \"%\")"


So does anyone know the code to accept double quotes in string constants?

SlyMaelstrom
Newbie Poster
21 posts since Oct 2005
Reputation Points: 15
Solved Threads: 2
 

I will say that the C/C++/Javaish/Perlish/etc/etc structure for working with escape sequences is a real treat compared to The basic language. The only way to do this, is to concantenate the character code value to the string where the double quote would be. It's sick, and it makes the code a lot less understandable when dealing with strings, but here is how your example would look:

str1 = "President Lincoln said " & chr(34) & "Four score and seven years ago..." & chr(34)


chr is the basic function to return the ascii value of a given character code. In this case, 34, which is ". This page has a cool list of them: http://www.lookuptables.com/

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Yep, that makes sense. Thank you.

SlyMaelstrom
Newbie Poster
21 posts since Oct 2005
Reputation Points: 15
Solved Threads: 2
 

But when i use Chr(34) it replaces a smart curly (“) double quote but i need to replace it with a straight double quote (") which. Is there a solution for this.

Ganesh_Kutty
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 1
 

Wow... here is another reason why bumping posts suck... I get a stupid email from a thread I subscribed to almost a year ago. Thanks for the spam, Ganesh.

SlyMaelstrom
Newbie Poster
21 posts since Oct 2005
Reputation Points: 15
Solved Threads: 2
 
Wow... here is another reason why bumping posts suck... I get a stupid email from a thread I subscribed to almost a year ago. Thanks for the spam, Ganesh.

:D

ShaunRigby
Newbie Poster
1 post since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

Hey use double times double quote for any escape sequence character like

[foo].ControlSource = "=IIf([foo]>0, 100*([foo1]/[foo2]) & ""%"", ""%"")"

kiran2010
Newbie Poster
2 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You