Jump to content

Using A Variable In A Variable?


Recommended Posts

Hiya,

I'm using a loop which looks up in a text file. When a certain condition is met then it writes information to a variable. But the condition can be met a few times so its always overwriting my original variable. Therefore I was wondering if it was possible to use a variable in a variable. (e.g. $UnRes & $ping = "Complete")

I've included the portion of my script below. I want $UnRes to go up one each time so first time in the loop it writes to variable $UnRes1, then $UnRes2 etc... (This includes my attempt at it ($UnRes & $ping = "Time Travel", although this errors so it obviously doesn't work, thought I'd leave it in to give you an example of what I'm trying to do!)

Any help greatly appreciated.

Mark

$ini = IniReadSectionNames("C:\temp\test.ini")

$count = $ini[0]

$ping = 1

Do
    $result = IniReadSection("C:\temp\test.ini", $ini[$ping]) 
    
    $count2 = $result[0][0]

    $ping2 = 1

    Do
        If $result[$ping2][1] = "Resolved" Then
            $UnRes & $ping = "Time Travel"
        EndIf
        $ping2 = $ping2 + 1
    Until $ping2 = $count2

    $ping = $ping + 1
Until $ping = $count
Link to comment
Share on other sites

:) hate looking at code that can be written another easier to understand way...

Rewriting it using For loops (and correcting your problem):

$ini = IniReadSectionNames("C:\temp\test.ini")

For $ping = 1 to $ini[0]
   $result = IniReadSection("C:\temp\test.ini", $ini[$ping])
   For $ping2 = 1 to $result[0][0]
      If $result[$ping2][1] = "Resolved" Then
         Assign("UnRes"&$ping, "Time Travel")
      EndIf
   Next
Next

I think you should use arrays instead, though.

#)

Link to comment
Share on other sites

Here:

$ini = IniReadSectionNames("C:\temp\test.ini")
Dim $UnResArray[$ini[0]+1]
For $ping = 1 to $ini[0]
   $result = IniReadSection("C:\temp\test.ini", $ini[$ping])
   For $ping2 = 1 to $result[0][0]
      If $result[$ping2][1] = "Resolved" Then
         $UnResArray[$ping] = "Time Travel"
      EndIf
   Next
Next
$UnResArray[0] = $ini[0]

NOTE: $UnResArray[0] is the length of the array.

#)

Edited by nfwu
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...