Sign in to follow this  
Followers 0
CyberSlug

Opt ExpandVarStrings fails?

12 posts in this topic

I get a message box saying The value of foo is and nothing else... Shouldn't it also print 42 ???

Opt("ExpandVarStrings", 1)

$foo = 42

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

Msgbox(4096,"", $example)

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
  • 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.

Share this post


Link to post
Share on other sites

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 $$$$ ? :)

Share this post


Link to post
Share on other sites

#7 ·  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!

Share this post


Link to post
Share on other sites

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)'


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  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!

Share this post


Link to post
Share on other sites

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!

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  
Followers 0