Alterego Posted May 17, 2005 Posted May 17, 2005 (edited) I seem to have had varying results in the past, although it is possible I was doing something wrong.As some of you may know by now ( ) I am fond of multi-tiered for loops due to the nature of automatically processing files in six languages, of three different types, for two different operating system and then either with or without images.So assume I have the following structure (which I do) in pseudocode:$lang = StringSplit('English,German,French,Dutch,Polish,esperanto') $wik = StringSplit('Wikipedia,Wiktionary,Wikiquote') $os = StringSplit('PPC,PALM') $img = StringSplit('TXT,IMG') For $a = 1 to lang[0] For $b = 1 to wik[0] For $c = 1 to os[0] For $d = 1 to img[0] logfile() Do a whole bunch of stuff tons of times over logfile() Next Next Next Next Func logfile() _FileWriteLog(@DesktopDir & '\log\' & $lang[$a] & '-' & $wik[$b] & '-' & $os[$c] & '-' & $img[$d] & '.txt') EndFuncThis does not seem work with my loop, now over 300 lines. A few questions that, if anyone could answer would help me out a lot:1) What is the actual scope of the for variable (local, global) ?2) Should it be available outside of the loop in a subfunction?3) Is it available outside of the subfunction?Because this does not seem to work for me it seems necessary to not use UDFs and repaste code etc... but that is not ideal.edit: update code to be more clear Edited May 17, 2005 by Alterego This dynamic web page is powered by AutoIt 3.
Ejoc Posted May 17, 2005 Posted May 17, 2005 (edited) I never rely on "global" variable if I can at all help it, avoids this problem. I know I'm not answering your scope question, but why not pass the variables to the function? logfile($a,$b,$c,$d) *EDIT I also use Opt("MustDeclareVars",1) in all my scripts, then you know if it's a local or global since you have to declare it. Edited May 17, 2005 by Ejoc Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Alterego Posted May 17, 2005 Author Posted May 17, 2005 I would like to heavily functionalize the program. It has become very hard to maintain and bloated as more exceptions have become necessary over time. This dynamic web page is powered by AutoIt 3.
Alterego Posted May 17, 2005 Author Posted May 17, 2005 Oh? Is there such a thing as For Global $a = 1 to 10? /runs to check This dynamic web page is powered by AutoIt 3.
Ejoc Posted May 17, 2005 Posted May 17, 2005 Global $a For $a = 1 to 10 Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Alterego Posted May 17, 2005 Author Posted May 17, 2005 That's the idea I was just having. This throws a scope error so it seems to work: Local $a = 0 For $a = 1 to 10 _increment() Next Func _increment() $a = $a + 1 EndFunc ClipPut($a) This dynamic web page is powered by AutoIt 3.
Ejoc Posted May 17, 2005 Posted May 17, 2005 I still say passing variables is better practice, you are incremement $a twice in your example: Local $a = 0 For $a = 1 to 10 Step 0 _increment($a) Next ClipPut($a) Func _increment(ByRef $val) $val = $val + 1; $val += 1 using beta EndFunc Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Alterego Posted May 17, 2005 Author Posted May 17, 2005 I see what you are getting at. It seems that it would guarantee the variables made it outside of the for loop and into the function no matter what. It requires just slightly more complex code but should be worth it in reliability. I'll update.. This dynamic web page is powered by AutoIt 3.
Alterego Posted May 17, 2005 Author Posted May 17, 2005 I wonder, what of the possibility of then handling exceptions in the functions themselves by ByRef'ing them the for loops variable and allowing them to increment/decrement them. And it works. This is great, a never-ending loop: Global $a For $a = 1 to 2 _decrement($a) Next Func _decrement(ByRef $a) $a = $a - 1 EndFunc This dynamic web page is powered by AutoIt 3.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now