kurtkafka Posted June 3, 2009 Share Posted June 3, 2009 A couple of weeks ago I started coding in AutoIT. I asked one or two questions in this forum and got quick and competent answers, so I now dare to open a thread with a question I would like to ask. In the code below are a lot of similar looking lines, which makes me wonder, if there is a possibility to simplify the code. What it does (roughly): $shouts_alle_50x6 is a two-dimensional array [x][6], where x can be everything from 1 to 7000 with strings inside. The function is supposed to find certain strings ($team_anzeige[$i] and $nick_anzeige[$i] in $shouts_alle_50x6[x][0]), and return all the lines, where a match was found in $gefiltert_anzeige_sub. It is not possible to say beforehand if and how many times $team_anzeige and $nick_anzeige will find a match. If $team_anzeige or $nick_anzeige are -1 there is no match to look after. I'm looking forward to your suggestions. expandcollapse popupFunc _filter_anzeige() Local $i Local $gef_teams_0, $gef_teams_1, $gef_teams_2, $gef_teams_3, $gef_teams_4, $gef_teams_5, $gef_teams_6, $gef_teams_7, $gef_teams_8, $gef_teams_9 Local $gef_nicks_0, $gef_nicks_1, $gef_nicks_2, $gef_nicks_3, $gef_nicks_4, $gef_nicks_5, $gef_nicks_6, $gef_nicks_7, $gef_nicks_8, $gef_nicks_9 Dim $gefunden_teams[UBound($shouts_alle_50x6)] Dim $gefunden_nicks[UBound($shouts_alle_50x6)] Dim $gefiltert_anzeige_sub = $shouts_alle_50x6; Übergabe aller Shouts in Filterroutine ;Teams finden, liefert ein array mit den Indexnummern der Teams For $i = 0 To 9 If $team_anzeige[$i] = -1 Then $dummy = 0 Else Select Case $i = 0 $gef_teams_0 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 1 $gef_teams_1 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 2 $gef_teams_2 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 3 $gef_teams_3 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 4 $gef_teams_4 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 5 $gef_teams_5 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 6 $gef_teams_6 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 7 $gef_teams_7 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 8 $gef_teams_8 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) Case $i = 9 $gef_teams_9 = _ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0) EndSelect EndIf Next If $team_anzeige[0] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_0) If $team_anzeige[1] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_1) If $team_anzeige[2] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_2) If $team_anzeige[3] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_3) If $team_anzeige[4] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_4) If $team_anzeige[5] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_5) If $team_anzeige[6] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_6) If $team_anzeige[7] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_7) If $team_anzeige[8] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_8) If $team_anzeige[9] <> -1 Then _ArrayConcatenate($gefunden_teams, $gef_teams_9) _ArraySort($gefunden_teams, 0) For $i = UBound($gefunden_teams) - 1 To 0 Step -1 If IsNumber($gefunden_teams[$i]) = 0 Then; wenn der Arrayeintrag keine Zahl ist _ArrayDelete($gefunden_teams, $i) EndIf Next ;Nicks finden For $i = 0 To 9 If $nick_anzeige[$i] = -1 Then $dummy = 0 Else Select Case $i = 0 $gef_nicks_0 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 1 $gef_nicks_1 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 2 $gef_nicks_3 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 3 $gef_nicks_3 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 4 $gef_nicks_4 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 5 $gef_nicks_5 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 6 $gef_nicks_6 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 7 $gef_nicks_7 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 8 $gef_nicks_8 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) Case $i = 9 $gef_nicks_9 = _ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1) EndSelect EndIf Next If $nick_anzeige[0] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_0) If $nick_anzeige[1] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_1) If $nick_anzeige[2] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_2) If $nick_anzeige[3] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_3) If $nick_anzeige[4] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_4) If $nick_anzeige[5] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_5) If $nick_anzeige[6] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_6) If $nick_anzeige[7] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_7) If $nick_anzeige[8] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_8) If $nick_anzeige[9] <> -1 Then _ArrayConcatenate($gefunden_nicks, $gef_nicks_9) _ArraySort($gefunden_nicks, 0) For $i = UBound($gefunden_nicks) - 1 To 0 Step -1 If IsNumber($gefunden_nicks[$i]) = 0 Then; wenn der Arrayeintrag keine Zahl ist _ArrayDelete($gefunden_nicks, $i) EndIf Next ; gefundene Nicks und Teams miteinander verknüpfen, doppelte löschen Dim $gefunden_teams_und_nicks[1] If IsArray($gefunden_teams) = 1 Then _ArrayConcatenate($gefunden_teams_und_nicks, $gefunden_teams) If IsArray($gefunden_nicks) = 1 Then _ArrayConcatenate($gefunden_teams_und_nicks, $gefunden_nicks) _ArrayDelete($gefunden_teams_und_nicks, 0); löscht den durch die Dimensionierung entstandenen ersten Eintrag _ArraySort($gefunden_teams_und_nicks, 0) For $i = UBound($gefunden_teams_und_nicks) - 2 To 0 Step -1;durch Nicks und Teams entstandene doppelte Einträge löschen If $gefunden_teams_und_nicks[$i] = $gefunden_teams_und_nicks[$i + 1] Then _ArrayDelete($gefunden_teams_und_nicks, $i + 1) EndIf Next ; $gefiltert_anzeige_sub aufbereiten, wenn Indexnummer nicht gefunden wird, wird Index $i aus $gefiltert_anzeige_sub gelöscht For $i = UBound($shouts_alle_50x6) - 1 To 0 Step -1 If _ArraySearch($gefunden_teams_und_nicks, $i) = -1 Then _ArrayDelete($gefiltert_anzeige_sub, $i) EndIf Next ;_ArrayDisplay($gefiltert_anzeige_sub) If IsArray($gefiltert_anzeige_sub) = 1 Then Return $gefiltert_anzeige_sub Else Return $shouts_alle_50x6 EndIf EndFunc ;==>_filter_anzeige Link to comment Share on other sites More sharing options...
evilertoaster Posted June 3, 2009 Share Posted June 3, 2009 (edited) Well, the way you have it structured now is maybe not ideal (since there's usually ways around doing what i'm going to post)...short of restructuring your variables to use perhaps a hash table or 3 dimensional array, you can use Assign() and Eval()- expandcollapse popupFunc _filter_anzeige() Local $i Local $gef_teams_0, $gef_teams_1, $gef_teams_2, $gef_teams_3, $gef_teams_4, $gef_teams_5, $gef_teams_6, $gef_teams_7, $gef_teams_8, $gef_teams_9 Local $gef_nicks_0, $gef_nicks_1, $gef_nicks_2, $gef_nicks_3, $gef_nicks_4, $gef_nicks_5, $gef_nicks_6, $gef_nicks_7, $gef_nicks_8, $gef_nicks_9 Dim $gefunden_teams[UBound($shouts_alle_50x6)] Dim $gefunden_nicks[UBound($shouts_alle_50x6)] Dim $gefiltert_anzeige_sub = $shouts_alle_50x6; Übergabe aller Shouts in Filterroutine ;Teams finden, liefert ein array mit den Indexnummern der Teams For $i = 0 To 9 If $team_anzeige[$i] = -1 Then $dummy = 0 Else Assign("gef_teams_"&$i,_ArrayFindAll($shouts_alle_50x6, $team_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 0)) EndIf If $team_anzeige[$i] <> -1 Then _ArrayConcatenate($gefunden_teams, Eval("gef_teams_"&$i) Next _ArraySort($gefunden_teams, 0) For $i = UBound($gefunden_teams) - 1 To 0 Step -1 If IsNumber($gefunden_teams[$i]) = 0 Then; wenn der Arrayeintrag keine Zahl ist _ArrayDelete($gefunden_teams, $i) EndIf Next ;Nicks finden For $i = 0 To 9 If $nick_anzeige[$i] = -1 Then $dummy = 0 Else Assign("gef_nicks_"&$i,_ArrayFindAll($shouts_alle_50x6, $nick_anzeige[$i], 0, UBound($shouts_alle_50x6), 0, 0, 1)) EndIf If $nick_anzeige[$i] <> -1 Then _ArrayConcatenate($gefunden_nicks, Eval("gef_nicks_"&$i) Next _ArraySort($gefunden_nicks, 0) For $i = UBound($gefunden_nicks) - 1 To 0 Step -1 If IsNumber($gefunden_nicks[$i]) = 0 Then; wenn der Arrayeintrag keine Zahl ist _ArrayDelete($gefunden_nicks, $i) EndIf Next ; gefundene Nicks und Teams miteinander verknüpfen, doppelte löschen Dim $gefunden_teams_und_nicks[1] If IsArray($gefunden_teams) = 1 Then _ArrayConcatenate($gefunden_teams_und_nicks, $gefunden_teams) If IsArray($gefunden_nicks) = 1 Then _ArrayConcatenate($gefunden_teams_und_nicks, $gefunden_nicks) _ArrayDelete($gefunden_teams_und_nicks, 0); löscht den durch die Dimensionierung entstandenen ersten Eintrag _ArraySort($gefunden_teams_und_nicks, 0) For $i = UBound($gefunden_teams_und_nicks) - 2 To 0 Step -1;durch Nicks und Teams entstandene doppelte Einträge löschen If $gefunden_teams_und_nicks[$i] = $gefunden_teams_und_nicks[$i + 1] Then _ArrayDelete($gefunden_teams_und_nicks, $i + 1) EndIf Next ; $gefiltert_anzeige_sub aufbereiten, wenn Indexnummer nicht gefunden wird, wird Index $i aus $gefiltert_anzeige_sub gelöscht For $i = UBound($shouts_alle_50x6) - 1 To 0 Step -1 If _ArraySearch($gefunden_teams_und_nicks, $i) = -1 Then _ArrayDelete($gefiltert_anzeige_sub, $i) EndIf Next ;_ArrayDisplay($gefiltert_anzeige_sub) If IsArray($gefiltert_anzeige_sub) = 1 Then Return $gefiltert_anzeige_sub Else Return $shouts_alle_50x6 EndIf EndFunc ;==>_filter_anzeige I think that should work... Edited June 3, 2009 by evilertoaster Link to comment Share on other sites More sharing options...
kurtkafka Posted June 3, 2009 Author Share Posted June 3, 2009 (edited) Thanks a lot for your help. I didn't know the functions assign and eval. I will have a look at your code trying to understand what is done with those functions. By the way, how is it done to post the coloured code? Edited June 3, 2009 by kurtkafka Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 4, 2009 Share Posted June 4, 2009 By the way, how is it done to post the coloured code? You use the [ autoit ] tags (minus the spaces). In the forum editor, the button with the AutoIt icon to add these tags has been disabled because the server-side support is quite buggy. I personally recommend you stick with the regular [ code ] and [ codebox ] tags, but you can manually apply [ autoit ] tags if you really want to. 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...
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