Jump to content

Refresh a variable that is used inside another variable


Go to solution Solved by millisys,

Recommended Posts

Hi all,

I have created a variable ($results) to contain variables to write to a CSV file. The variables are assigned many times throughout the script. I noticed that the $var1,$var2,$var3 variables inside the $results variable to be written to the CSV file are not acknowledging the values if they occur after the $results declaration in the script.

Probably an example will better explain. Is there a way to 'refresh' the $results variable before it writes so that it can capture values from later variables? I looked at ReDim but that seems to be only for arrays.

Thank you

$var1 = 0
$var2 = 0
$var3 = 0
$results = $var1 & "," & $var2 & "," & $var3
$var1 = 1
$var2 = 2
$var3 = 3
ConsoleWrite($results)
Link to comment
Share on other sites

variable assingments are static, you would need to redeclare $results with the new $var1 & "," & $var2 & "," & $var3

It seems that you can create a function, and just call with the new values:
 

$var1 = 0
$var2 = 0
$var3 = 0
$yourvariable = SomeFunc($var1,$var2,$var3)
MsgBox(1,1,$yourvariable)
$var1 = 1
$var2 = 2
$var3 = 3
$yourvariable = SomeFunc($var1,$var2,$var3)
MsgBox(1,1,$yourvariable)
$yourvariable = SomeFunc(5,6,7)
MsgBox(1,1,$yourvariable)

Func SomeFunc($1,$2,$3)
    ConsoleWrite($1 & "," & $2 & "," & $3 & @CRLF)
    Return $1 & "," & $2 & "," & $3
EndFunc
Exit
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...