Solved

work around for command interperter quoting

Posted on 1998-12-10
5
140 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
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
waty earned 100 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

808 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