Solved

work around for command interperter quoting

Posted on 1998-12-10
5
138 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now