Jump to content

[Solved] variable in string?


Recommended Posts

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
Link to comment
Share on other sites

$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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

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
Link to comment
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
 Share

  • Recently Browsing   0 members

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