[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

work around for command interperter quoting

Posted on 1998-12-10
5
Medium Priority
?
146 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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 how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 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