darkshadow791 Posted September 28, 2006 Share Posted September 28, 2006 I was wondering if there was an easy way of having an if loop based on an array... I'm not good at explaining very well... Basically I have a really long array (I.E. $array[0] - $array[100] or something like that) And I want to make an if loop that will do a certain function based on what $array returns... i.e. if $array[0] is returned true it will do func(0) or $array[1] will do func(1) etc. It can be something besides an array if there's an easier way of doing it... I basically want something like this that can go to 200 or w/e I please without having to copy and paste it 200 times... Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
xcal Posted September 28, 2006 Share Posted September 28, 2006 Something like... For $i = 1 to UBound($yourarray) - 1 If $yourarray[$i] = something Then somefunc() EndIf Next How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Nezoic Posted September 29, 2006 Share Posted September 29, 2006 hmm, it sounds like a for loop is what you want to use. Maybe post some code or explain what you're doing exactly, might be able to find a more efficent way of doing it. Link to comment Share on other sites More sharing options...
ame1011 Posted September 29, 2006 Share Posted September 29, 2006 (edited) I was wondering if there was an easy way of having an if loop based on an array... I'm not good at explaining very well... Basically I have a really long array (I.E. $array[0] - $array[100] or something like that) And I want to make an if loop that will do a certain function based on what $array returns... i.e. if $array[0] is returned true it will do func(0) or $array[1] will do func(1) etc. It can be something besides an array if there's an easier way of doing it... I basically want something like this that can go to 200 or w/e I please without having to copy and paste it 200 times... for $x = 0 to Ubound($array) - 1 $value = $array[$x] if $value = 'true' then true_func() elseif $value = 'false' then false_func() endif next Although we dont mind helping those who require it, you should really become accustomed to searching through the helpfile. A simple search on arrays and conditionals would have given you all that you needed to know to complete this snippet of code. Edited September 29, 2006 by ame1011 [font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font] Link to comment Share on other sites More sharing options...
darkshadow791 Posted September 29, 2006 Author Share Posted September 29, 2006 I don't actually have the code yet I'm planning a project in the future but I was planning on having a value (lets say $x) be user inputted and based on that value it will run a func($x) and based on the value of func($x) ( $y = func($x) )it will return another func, func2($y) and I was seeing if there was a simple way to have it set it so I don't have to copy / paste it... I knew about for loop's but I'm not very good with those and I did look through the help file but I couldn't really find a concrete answer... But I think I might be able to figure it out based on what you guy's posted, thanks. Ex. if you couldn't figure out my descript: $x = userinputbox ( blah blah blah ) func($x) $y = func($x) If $y = 1 func2(1) If $y = 2 func2(2) etc... Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 29, 2006 Share Posted September 29, 2006 I don't actually have the code yet I'm planning a project in the future but I was planning on having a value (lets say $x) be user inputted and based on that value it will run a func($x) and based on the value of func($x) ( $y = func($x) )it will return another func, func2($y) and I was seeing if there was a simple way to have it set it so I don't have to copy / paste it... I knew about for loop's but I'm not very good with those and I did look through the help file but I couldn't really find a concrete answer... But I think I might be able to figure it out based on what you guy's posted, thanks. Ex. if you couldn't figure out my descript: $x = userinputbox ( blah blah blah ) func($x) $y = func($x) If $y = 1 func2(1) If $y = 2 func2(2) etc... You need to take much more, or much less, of whatever it is you're on... While recovering from the [overdose|withdrawl], how about coding a quick example of what you're talking about, with only say three elements? Get it working in small scale (with help if needed) then scale it up to hundreds of "functions". 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 More sharing options...
Uten Posted September 29, 2006 Share Posted September 29, 2006 I have no clue what your after but this might give you somthing to think about. It is not tested $arr[0][0] = 0 $arr[0][1] = 'func0' $arr[1][0] = 1 $arr[1][1] = 'func1' Func ArrayCallLoop(ByRef $arr) Local $i For $i = 0 to UBound($arr) - 1 if $arr[$i][0] then call $arr[$i][1] Next EndFunc Func func0() ; Do Work EndFunc Func func1() ; Do Work EndFunc Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
ame1011 Posted September 29, 2006 Share Posted September 29, 2006 why only 100 functions? I say go for 1000 [font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font] Link to comment Share on other sites More sharing options...
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