?
Solved

work around for command interperter quoting

Posted on 1998-12-10
5
Medium Priority
?
144 Views
Last Modified: 2010-05-03
I have a application that needs to send quotes " " via a
textbox, however the command interperter under windows has different ideas. To do it properly I need the send a back slash before each quote like this: \"Hello World\"

Question: Could I somehow force VB to place a back slash before any quotes found in a TextBox?
0
Comment
Question by:Biffo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
waty earned 400 total points
ID: 1449238
Use :
ReplaceString(sStr, """", "\""")

Function ReplaceString(sSearch As String, sSearchFor As String, sReplaceWith As String) As String
   ' *** Searches the sSearch variable for sSearchFor
   ' *** and replaces it with sReplaceWith.

   On Error GoTo ERROR__ReplaceString

   Dim lFoundLoc        As Long   ' Location of match.
   Dim lLenRemove       As Long   ' Length of string being replaced.

   ' *** Set length of original text to skip.
   lLenRemove = Len(sSearchFor)    ' Set location of match.

   lFoundLoc = InStr(1, sSearch, sSearchFor)

   ' If sSearchFor isn't found in sSearch
   ' just return the original string.
   If lFoundLoc = 0 Then
      ReplaceString = sSearch
      ' If match is found, return original string up to match
      ' location, concatenate new text, and search the rest of
      ' the string recursively for additional matches.
   Else
      ReplaceString = Left(sSearch, lFoundLoc - 1) & sReplaceWith & ReplaceString(Mid(sSearch, lFoundLoc + lLenRemove), sSearchFor, sReplaceWith)
   End If

EXIT_ReplaceString:
   Exit Function

ERROR__ReplaceString:
   ' Print error to Debug window and don't interrupt query.
   Debug.Print "Error Replacing String """ & sSearchFor & """ with """ & sReplaceWith & """ in text """ & sSearch & """"
   ' If there is an error, return original string
   ' and exit the function.
   ReplaceString = sSearch
   Resume EXIT_ReplaceString

End Function

0
 
LVL 2

Author Comment

by:Biffo
ID: 1449239
I have one question: are you placing ReplaceString(sStr, """", "\""") ?  I am thinking something like the below:



Private Sub Text1_Change()

Text1 = sStr
ReplaceString(sStr, """", "\""")

End Sub

0
 
LVL 14

Expert Comment

by:waty
ID: 1449240
If Text1 contains your string :

Text1.Text = ReplaceString(Text1.Text, """", "\""")
0
 
LVL 2

Author Comment

by:Biffo
ID: 1449241
Oh wow, YES! Thanks waty.....now my quotes aren't getting
zaped by the shell.
0
 
LVL 2

Author Comment

by:Biffo
ID: 1449242
Hey waty, if you don't mind me asking, how would you
skip the search and replace if \" already exists in a Text1 ?
Whould that be difficult?
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question