Jump to content

Help With variable


sponk
 Share

Recommended Posts

Hey

My first topic here, seems like a nice forum (have used it much as a guest)

Now I have a problem with a script and think its quite basic, but dunno how to solve it.

I have a part of my script (cut down to highlight the problem):

#############

Run($File1)

..

..

..

Send($Load1)

Run($File2)

..

..

..

Send($Load2)

Run($File3)

..

..

..

Send($Load3)

ect

ect

##############

So instead of making script for each variable which are the same, only differs in variable, I want it to be like this:

Run($File1)

..

..

..

Send($Load1)

then add +1 to $file and +1 to $Load and repeat.

I have an ini file for all the $file and $Load so I want it to optional how many I want to read. Dunno if I explained my problem, for you to understand, else I try to reexplain.

Link to comment
Share on other sites

sponk,

Now that you've read the stuff as advised by the heavy hitters, here's some code to chew on.

;
; the following demonstrates looping through predefined variables using eval
;

local $var1=10,$var2=11,$var3=12,$var4=13,$var5=14,$var6=15,$var7=16,$var8=17,$var9=18,$var10=19

for $i = 1 to 10
    c(eval('var' & $i) & ' i = ' & $i)
    if eval('var' & $i) = 15 then c('hit on $var6')
next

;
; the following demonstrated looping through a 2X array 
;

local $a10[10][2] = [['act1_1','act1_2'], _
                    ['act2_1','act2_2'], _
                    ['act3_1','act3_2'], _
                    ['act4_1','act4_2'], _
                    ['act5_1','act5_2'], _
                    ['act6_1','act6_2'], _
                    ['act7_1','act7_2'], _
                    ['act8_1','act8_2'], _
                    ['act9_1','act9_2'], _
                    ['act10_1','act10_2']]

for $i = 0 to ubound($a10,1) - 1
    c('invoking action = ' & $a10[$i][0] & ' followed by action ' & $a10[$i][1])
next

func c($str)
    consolewrite('> ' & $str & @lf)
EndFunc

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

If you really have all the values ahead of time, then walking through an array of values is more efficient, as mentioned.

If you use various values at different points in the script though, you could just turn it into a function:

_MyFunc($File1, $Load1)
_MyFunc($FileX, $LoadX)
_MyFunc($MyFile, $MyLoad)
_MyFunc($YourFile, $YourLoad)

Func _MyFunc($sFile, $sLoad)
    Run($sFile)
    ; ..
    ; ..
    ; ..
    Send($sLoad)
EndFunc

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You can use arrays or use variable functions as this example

example

For $i = 1 To 5

If Assign("variable" & $i , "Hello" & $i ) Then MsgBox(4096, "", Eval("variable" & $i ))

Next


MsgBox(4096, "", _
Eval("variable1") & @CRLF & _
Eval("variable2") & @CRLF & _
Eval("variable3") & @CRLF & _
Eval("variable4") & @CRLF & _
Eval("variable5"))

صرح السماء كان هنا

 

Link to comment
Share on other sites

sponk,

Since you mentioned that you have the value pairs in an "ini" file and that you want to "optionally" run these pairs, psalty's solution with rudimentary selection logic makes the most sense.

read ini

|

|

execute pair? ---> yes call psalty's function

|

| no

|

read next ini record

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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