Jump to content
Sign in to follow this  
Hadez

Quotation marks around a $Variable?

Recommended Posts

Hadez

Hi, i was searching for a while about how to have a variable inside quotation marks, as when i add "$variable" as a commandline argument, it is seen as a string. Is there a way to have the variable inside the " "? My code is similar to this:

$chkFileNamePath = FileRead($chkMovePath)

I need to add the $chkFileNamePath as a commandline parameter. This parameter needs to be inside Quotationmarks. got any ideas as to how i can do this? Thanks alot for your help :idea:

Share this post


Link to post
Share on other sites
omikron48

Global $string = "variable"
MsgBox(0x2000, "Variable String", "This is how you add a " & $string & " in the middle of a string.")

You don't want to put a variable within a string because, under normal conditions, the parser will not evaluate the variable if it's contained within quotes. You can however concatenate however many strings or variables you want into one big string.

OR in case you need to include a double quote inside a string, you can either use two double quotes or enclose a double quote with single quotes.

Global $string = "variable"
MsgBox(0x2000, "Quote Example", "This is how you add a """ & $string & '" in the middle of a string.')
Edited by omikron48

Share this post


Link to post
Share on other sites
Hadez

Hi mate, thanks for your reply, but im kinda lost with this. Am i right in understanding that instead of giving the commandline the variable, i should process the variable beforehand to make a string and then send that string to commandline?

The example im using is this:

$chkFileNamePath = FileRead($chkMovePath)
$ppMKTLine = $ppMLocation & ' -a ' & $chkFileNamePath & ' -b -c ' & $ppName & ' ' & $ppFileLocation

The requirement is that $chkFileNamePath and $ppFileLocation both need to be inside "" so in a perfect world where everything worked,it would look like:

$chkFileNamePath = FileRead($chkMovePath)
$ppFileLocation = FileRead($NewLinePath)

$ppMKTLine = $ppMLocation & ' -a ' & "$chkFileNamePath" & ' -b -c ' & $ppName & ' ' & "$ppFileLocation"

If i replace the Variables with a string it runs in command line fine, but then messes up with the "" being seen as a string. Im not too sure how i would make that $ppMKTLine a string value though as the variables by nature would change. Any pointers in the right direction would be more than welcome as im going round in circles :idea: Thanks again for your help.

Share this post


Link to post
Share on other sites
omikron48

;create test text file
Global $filename = "C:\_My Test File\message.txt"
Global $filehandle = FileOpen($filename, 10)
FileWriteLine($filehandle, "Hello world!")
FileClose($filehandle)

;what it looks like in commandline
MsgBox(0, "Commandline", 'notepad.exe "' & $filename & '"', "")

;open test text file in notepad
RunWait('notepad.exe "' & $filename & '"', "")

;clean up test text file
FileDelete($filename)

In this example, I'm forced to resort to enclosing the actual file path within double quotes in the string value since commandline doesn't like it when your parameter has a whitespace in it (in this case, the folder name).

The fastest way to answer your question would be to set Opt for ExpandVarStrings to 1, but that's bad practice to use when it isn't necessary.

Edited by omikron48

Share this post


Link to post
Share on other sites
Hadez
:) Nice 1. U solved the problem. It doesnt like to be surrounded by "" but is more than happy with having '"' :( Nice work around mate. Thanks alot :idea:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×