JohnBailey Posted June 26, 2007 Share Posted June 26, 2007 I use the following switch several times through out my script (because it does a series of different checks). The problem is any time I want to make an addition to the group I've got to do a SearchReplace. I want to use a var instead but I don't know how. So here's the Switch, then I'll show you what I'm trying to do. *Note: I cannot post the entire working script due to security reasons. I can make a mock-script if need be Switch $AccountsArray[2] case 0656102,0652568,2634443,435137,87588,57567380,18900977,98668777,895600746,0002310,1321468 case 964783,4553245 case Else EndSwitchoÝ÷ Øæï¬+ay·¥£"Yè· +z0z÷«#f¶¼¢h²0Â#§¶Ú¡«¢+ØÀÌØíɽÕÀÄôÀØÔØÄÀÈ°ÀØÔÈÔØà°ÈØÌÐÐÐÌ°ÐÌÔÄÌÜ°àÜÔàà°ÔÜÔØÜÌàÀ°ÄàäÀÀäÜÜ°äàØØàÜÜÜ°àäÔØÀÀÜÐØ°ÀÀÀÈÌÄÀ°ÄÌÈÄÐØà(ÀÌØíɽÕÀÈôäØÐÜàÌ°ÐÔÔÌÈÐÔ)MÝ¥Ñ ÀÌØí½Õ¹ÑÍÉÉålÉt(%ÍÀÌØíɽÕÀÄ(í¼Ñ¡¥Ì¥ÉÍÐÑ¡¥¹½ÈÑ¡¥ÌɽÕÀ(ÍÀÌØíɽÕÀÈ(í¼Ñ¡¥Ìͽ¹Ñ¡¥¹½ÈÑ¡¥ÌɽÕÀÈ$$$$$$(%ͱÍ(í¼Í½µÑ¡¥¹±Í½È±°½Ñ¡È½Õ¹ÑÌ()¹MÝ¥Ñ A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 26, 2007 Author Share Posted June 26, 2007 maybe this is a stupid question. If it is, please let me know. There may be a much better way of accomplishing this. A decision is a powerful thing Link to comment Share on other sites More sharing options...
Leighwyn Posted June 26, 2007 Share Posted June 26, 2007 You could use the function _ArraySearch( ) with the Array.au3 file (remember to include it). Syntax: _ArraySearch($avArray, $vWhat2Find, $iStart = 0, $iEnd = 0,$iCaseSense=0, $fPartialSearch = False) If it doesn't find your number, it returns -1 and if it does, it returns the index where it found it. I would also use it as a Select rather than Switch, since it makes the code easier for me.. #inclue "Array.au3" Select Case _ArraySearch($group1, $AccountsArray[2]) <> -1 [stuff for when the account # is in group 1] Case _ArraySearch($group2, $AccountsArray[2]) <> -1 [stuff for when the account # is in group 2] Case Else [stuff for when the account # is in neither] EndSelect Link to comment Share on other sites More sharing options...
JohnBailey Posted June 26, 2007 Author Share Posted June 26, 2007 I couldn't figure out how to use an array, and that's the answer! Thank you! I've never actually used Select before in any language. haha it comes up eventually, eh? Thanks sir/ma'am A decision is a powerful thing Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 26, 2007 Share Posted June 26, 2007 (edited) One cheesey trick for putting multiple cases in like that is: $String = "0656102,0652568,2634443,435137,87588,57567380,18900977,98668777,895600746,0002310,1321468" If $StringInStr($String, $AccountsArray[2]) Then ; ElseIf StringInStr("964783,4553245", $AccountsArray[2]) Then ; Else ; EndIf Of course, I don't code like that any more... much. P.S. One reason not to do that is that you might get matches on partial strings, like 56. Edited June 26, 2007 by PsaltyDS 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...
JohnBailey Posted June 26, 2007 Author Share Posted June 26, 2007 PsaltyDS, oh I didn't even think of doing it that way I think I'm going to stick with the Array method though because I actually have to change how the script is getting the account numbers.Nonetheless, is it better to use Select or If ?I know this may come down to personal preferences, but I'd really like to know thoughts on this choice! A decision is a powerful thing Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 26, 2007 Share Posted June 26, 2007 PsaltyDS, oh I didn't even think of doing it that way I think I'm going to stick with the Array method though because I actually have to change how the script is getting the account numbers.Good choice. Arrays are how I do that kind of thing these days; I shouldn't have mentioned old bad habits.Nonetheless, is it better to use Select or If ?I know this may come down to personal preferences, but I'd really like to know thoughts on this choice!Probably no difference. Switch and Select are just alternate ways to write a long chain of If/ElseIf/Else/EndIf. They exist for human readability and ease of maintenance, not because they work differently from 'If'. I can't prove it (others on this forum can), but Switch, Select, and If all probably call the exact same compiled code inside the interpreter. 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...
JohnBailey Posted June 26, 2007 Author Share Posted June 26, 2007 Good choice. Arrays are how I do that kind of thing these days; I shouldn't have mentioned old bad habits.Actually, I appreciate it because it reminds me of concepts that I've overlooked.I can't prove it (others on this forum can), but Switch, Select, and If all probably call the exact same compiled code inside the interpreter.That would be FASCINATING to know. Maybe someone can impart the answer to your statement A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 26, 2007 Author Share Posted June 26, 2007 oh and thanks for the explanation! A decision is a powerful thing 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