Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with using quote characters

Status
Not open for further replies.

wallst32

MIS
Joined
Apr 14, 2003
Messages
545
Location
US
Hello; first off I'm a system's administrator. I know NT shell, but only very basic VBS.

What I am trying to do is create a VBS with a input box; then take the variable and pass it to a command line.

All of this works just fine, expect when my variable has a space character.

The basic framework I have is:

attach = InputBox("Enter attachment file name:")
MsgBox("Filename=" & attach)

Set objShell = CreateObject("WScript.shell")
objShell.Run ("my command -attach" & attach)

Now suppose the variable "attach" has a space; lets say the value is "my document.txt". The proper way to run my commmnad line would be:

-attach "my document.txt"

How do I do this in VBS?

Thanks.


 
objShell.Run ("my command -attach [!]""[/!]" & attach [!]& """"[/!])



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
George - Works perfectly; thanks.
 
Msgbox Chr(34) & "Hello World!" & Chr(34)

Swi
 
This comes up so often that I include this function in my toolbox just to reduce my typing:


MsgBox qq("Hello World")

Function qq(strIn)
qq = Chr(34) & strIn & chr(34)
End Function

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Not only is [tt]Chr(34)[/tt] awkward to read, one should at least avoid the slow Variant version and use [tt]Chr$(34)[/tt]. Of course that still looks clunky and requires those extra concatenation operations.

Poor performance, ugly code with magic numbers. Why do people do this again?
 
Agreeing with explicit Chr$(), I do it because I find it easier than counting "s. Especially when I only have to do it once. Perhaps this would make you feel better:

MsgBox qq("FOO")

Function qq(strIn As String)
Const QUOTE As String = """"
qq = QUOTE & strIn & QUOTE
End Function

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
You are right about the use of $ but I find it just as difficult to read using the multiple quotes. Of course this is just my preference. [smile]

Swi
 
Well considering that it's just a Run method on the WSH WShell object, it isn't as if the program will be counting the microseconds to get the job done. ;)

At least you'd hope these aren't being done thousands of times in a row.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top