Jump to content
Sign in to follow this  
meokey

[Solved] variable in string?

Recommended Posts

meokey

Is it possible to make the following work? Thanks.

; test

$inifile="test.ini"
IniWrite($inifile, "English", "string1", '"There is a(an) " & $var & " in the box."')

dim $aaa
$var="apple"
Assign("aaa",IniRead($inifile,"English","string1", ""))
MsgBox(0, "", $aaa)
Edited by meokey

Share this post


Link to post
Share on other sites
Authenticity

$var = "apple" has to be declared or assigned before using it.

; test

Dim $aaa, $var="apple", $inifile="test.ini"

IniWrite($inifile, "English", "string1", "There is a " & $var & " in the box.")

;Assign("aaa",IniRead($inifile,"English","string1", ""))
$aaa = IniRead($inifile,"English","string1", "")
MsgBox(0, "", $aaa)
Edited by Authenticity

Share this post


Link to post
Share on other sites
meokey

Thanks for replying, but sorry I didn't make myself clear.

I want to put $var into the string, and assign it LATER when I know what's $var. OK, I modify the code a little:

; test

$inifile="test.ini"
IniWrite($inifile, "English", "string1", '"There is a(an) " & $var & " in the box."')

dim $aaa
$var="apple"
Assign("aaa",IniRead($inifile,"English","string1", ""))
MsgBox(0, "", $aaa)
$var="pear"
Assign("aaa",IniRead($inifile,"English","string1", ""))
MsgBox(0, "", $aaa)
Edited by meokey

Share this post


Link to post
Share on other sites
Jos

How about:

; test

$inifile="test.ini"
IniWrite($inifile, "English", "string1", '"There is a(an) $var in the box."')

dim $aaa
$var="apple"
$aaa = StringReplace(IniRead($inifile,"English","string1", ""),"$var",$var)
MsgBox(0, "", $aaa)
$var="pear"
$aaa = StringReplace(IniRead($inifile,"English","string1", ""),"$var",$var)
MsgBox(0, "", $aaa)

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

Share this post


Link to post
Share on other sites
martin

Thanks for replying, but sorry I didn't make myself clear.

I want to put $var into the string, and assign it LATER when I know what's $var. OK, I modify the code a little:

; test
 
 $inifile="test.ini"
 IniWrite($inifile, "English", "string1", '"There is a(an) " & $var & " in the box."')
 
 dim $aaa
 $var="apple"
 Assign("aaa",IniRead($inifile,"English","string1", ""))
 MsgBox(0, "", $aaa)
 $var="pear"
 Assign("aaa",IniRead($inifile,"English","string1", ""))
 MsgBox(0, "", $aaa)

; test
OPt("ExpandVarStrings",1);<--see the help for explanation
$inifile="test.ini"
$variablename = "var"
IniWrite($inifile, "English", "string1", "There is a(an) $" & $variablename & "$ in the box.")

dim $aaa
$var="apple"

Assign("aaa",IniRead($inifile,"English","string1", ""))
MsgBox(0, "", $aaa)
$var="pear"
Assign("aaa",IniRead($inifile,"English","string1", ""))
MsgBox(0, "", $aaa)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
meokey

Thanks Martin and Jos. This is exactly what I want.

; test
OPt("ExpandVarStrings",1);<--see the help for explanation
$inifile="test.ini"
$variablename = "var"
IniWrite($inifile, "English", "string1", "There is a(an) $" & $variablename & "$ in the box.")

dim $aaa
$var="apple"

Assign("aaa",IniRead($inifile,"English","string1", ""))
MsgBox(0, "", $aaa)
$var="pear"
Assign("aaa",IniRead($inifile,"English","string1", ""))
MsgBox(0, "", $aaa)
Edited by meokey

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  

×