Jump to content

Recommended Posts

Posted

Not only does this not display the data contained in $foo, also, if you add some text to the end of the string like this:

$example = "The value of foo is $foo blah blah blah"

All you will get is:

The value of foo is

Which obviously has everything after the variable truncated.
Posted

Just like environment variables, you have to add the special char also at the end.

If you want to use the variable $foo, use it like this $foo$.

I adjusted your example:

Opt("ExpandVarStrings", 1)

$foo = 42

$example = "The value of foo is $foo$"

Msgbox(4096,"", $example)
  • Developers
Posted

Just like environment variables, you have to add the special char also at the end.

If you want to use the variable $foo, use it like this $foo$.

I adjusted your example:

Opt("ExpandVarStrings", 1)

$foo = 42

$example = "The value of foo is $foo$"

Msgbox(4096,"", $example)

<{POST_SNAPBACK}>

Correct, but shouldn't this also work ?

Opt ("ExpandVarStrings", 1)
$foo = 42
$example = "The value of $foo is $foo$"
MsgBox(4096, "", $example)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
  • The help file does not describe the usage like that.

    "The value of var1 is $var1".

  • In my opinion, requiring a trailing $ removes most of the usefulness of this feature since it still requires manual editing of the variable to get the syntax correct. If you have to manually edit the variable, then why not just add the concatenation operator and be done with it?
  • JdeB is right. If it does require both leading/trailing $, then it should not be necessary to use $$ to escape $'s since the word needs to have both before it is a variable. That means "The value of $foo is $foo$" should print correctly.
However, in the end, I don't really care how it works, I guess; I don't intend to use this feature as it makes code slightly more vague to read.
Posted

Opt("ExpandVarStrings", 1)
$foo = 42
$example = 'The value of $$foo is $foo$'
Msgbox(4096,"", $example)

This outputs 'The value of $foo is 42'

Just got to have lots of $$$$ ? :)

Posted (edited)

In the end it doesn't work yet :)

EDIT: Okay, MHz's method works, but the documentation is wrong then. And the truncation thing that Valik pointed out is a bug.

I really would like to use this feature in AutoBuilder when doing code generation:

'GuiCreate("MyGUI", ' & $w & ", " & $h & ",(@DesktopWidth-" & $w & ")/2, (@DesktopHeight-" & $h & ")/2 , 0x04CF0000)"

versus

'GuiCreate("MyGUI", $w , $h ,(@DesktopWidth - $w )/2, (@DesktopHeight - $h )/2 , 0x04CF0000)'

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
  • Developers
Posted

In the end it doesn't work yet :)

I really would like to use this feature in AutoBuilder when doing code generation:

'GuiCreate("MyGUI", ' & $w & ", " & $h & ",(@DesktopWidth-" & $w & ")/2, (@DesktopHeight-" & $h & ")/2 , 0x04CF0000)"

versus

'GuiCreate("MyGUI", $w , $h ,(@DesktopWidth - $w )/2, (@DesktopHeight - $h )/2 , 0x04CF0000)'

<{POST_SNAPBACK}>

CyberSlug,

I think it should be:

'GuiCreate("MyGUI", $w$ , $h$ ,(@DesktopWidth - $w$ )/2, (@DesktopHeight - $h$ )/2 , 0x04CF0000)'

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

Actually, here's what I want--I need the double @ symbol:

Opt("ExpandVarStrings", 1)
Dim $w = 300, $h = 200
$output = 'GuiCreate("MyGUI", $w$, $h$, (@@DesktopWidth-$w$)/2, (@@DesktopHeight-$h$)/2, 0x04CF0000)'

MsgBox(4096,"Result", $output)
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
  • Administrators
Posted

Yeah it needs a leading and trailing $ - otherwise you wouldn't be able to do

$foo = "there"

msgbox(0, "", "hello$foo$hello")


 

Posted

Workaround for arrays is to use Assign:

Opt("ExpandVarStrings", 1)

Dim $x = StringSplit("ABCD","");creates array $x[0], ..., $x[4]
For $i = 0 To 4
   Assign("x" & $i, $x[$i]);create vars x0, ..., x4
Next

MsgBox(4096, "Example", "One $x1$ Two $x2$ Three $x3$ Four $x4$")
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...