Jump to content

variable looping help needed


Recommended Posts

I have mutlipe arrays setup such as:

Dim $Test1[3]

$test[0] = "stuff1"

$test[1] = "stuff2"

$test[2] = "stuff3"

Dim $Test2[3]

$test[0] = "stuff4"

$test[1] = "stuff5"

$test[2] = "stuff6"

Dim $Test3[3]

$test[0] = "stuff7"

$test[1] = "stuff8"

$test[2] = "stuff9"

I want to setup a loop to execute items in these arrays. Executing array $test1, then $test 2 etc...

I can't figure out how to assign my loop number to $test to dynamically name the variable.

Maybe I should just be using 2 dimensional arrays?

Example: (I know this isn't actualy code, but more of a visual example)

Dim $Loop = 1

Do

Shellexecutewait($Test &$loop[0])

Shellexecutewait($Test &$loop[2])

Shellexecutewait($Test &$loop[3])

$loop = $loop + 1

Until $loop = 4

Link to comment
Share on other sites

Maybe...

Dim $Test[3]
$Test[0] = "stuff1" 
$Test[1] = "stuff2" 
$Test[2] = "stuff3" 

Dim $Test1[3]
$Test1[0] = "stuff4" 
$Test1[1] = "stuff5" 
$Test1[2] = "stuff6" 

Dim $Test2[3]
$Test2[0] = "stuff7" 
$Test2[1] = "stuff8" 
$Test2[2] = "stuff9" 

Dim $Loop = 0

Do
    
    MsgBox(0x0, $Loop, "test = " & $Test[$Loop] & @CRLF & "test1 = " & $Test1[$Loop] & @CRLF & "test2 = " & $Test2[$Loop] & @CRLF, 3)

    $Loop = $Loop + 1

Until

8)

NEWHeader1.png

Link to comment
Share on other sites

I have mutlipe arrays setup such as:

Dim $Test1[3]

$test[0] = "stuff1"

$test[1] = "stuff2"

$test[2] = "stuff3"

Dim $Test2[3]

$test[0] = "stuff4"

$test[1] = "stuff5"

$test[2] = "stuff6"

Dim $Test3[3]

$test[0] = "stuff7"

$test[1] = "stuff8"

$test[2] = "stuff9"

I want to setup a loop to execute items in these arrays. Executing array $test1, then $test 2 etc...

I can't figure out how to assign my loop number to $test to dynamically name the variable.

Maybe I should just be using 2 dimensional arrays?

Example: (I know this isn't actualy code, but more of a visual example)

Dim $Loop = 1

Do

Shellexecutewait($Test &$loop[0])

Shellexecutewait($Test &$loop[2])

Shellexecutewait($Test &$loop[3])

$loop = $loop + 1

Until $loop = 4

OK, the following example is based upon a supposition that you're going to want to be able to add or subtract the various "$Testn" arrays and have a reusable script component for your processing. Basically, if you want to add a "$Test4" array, you shouldn't have to modify the core Do... Until loop.

I would have posted a lot sooner, but it took me a while to figure out the (in the end, simple) way to work around not being able to use Eval() on array elements. Hope this is of use to you, and anyone who may have run into the Eval() speedbump I had hit.

Note, the sample code assumes a set of arrays that all start with "$Test" followed by a number. If removing arrays in the middle of a number sequence, be sure to double-check the numbering since a skip from 1 to 3 (after removing "2") would stop processing after "1":

Dim $Test1[3]
$Test1[0] = "stuff1"
$Test1[1] = "stuff2"
$Test1[2] = "stuff3"

Dim $Test2[3]
$Test2[0] = "stuff4"
$Test2[1] = "stuff5"
$Test2[2] = "stuff6"

Dim $Test3[3]
$Test3[0] = "stuff7"
$Test3[1] = "stuff8"
$Test3[2] = "stuff9"

$iIncrement = 1
$iNextTestExist = IsDeclared("Test" & $iIncrement)

If $iNextTestExist <> 0 Then
    ConsoleWrite("Starting Loop..." & @CRLF)
    Do
        Dim $aActiveArray = Eval("Test" & $iIncrement)
        ConsoleWrite("Source Array = Test" &$iIncrement &@CRLF)
        $iRange = (UBound($aActiveArray) - 1)
        For $i = 0 To $iRange
            ConsoleWrite("Element "&$i &" = " &$aActiveArray[$i] &@CRLF)
        Next
        $iIncrement += 1
        $iNextTestExist = IsDeclared("Test" & $iIncrement)
    Until $iNextTestExist = 0
    ConsoleWrite("End of Loop..." & @CRLF)
EndIf

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

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...