Sign in to follow this  
Followers 0
millisys

Refresh a variable that is used inside another variable

3 posts in this topic

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)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

Thank you jdelaney. Good idea! I will go with creating a function to redeclare the $results internal variables.

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