MatteoGuallini Posted May 9, 2006 Share Posted May 9, 2006 I need to sort a 2D array selecting an element someone can help me? Thanks http://www.vigevano-prabis.it/ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 9, 2006 Moderators Share Posted May 9, 2006 (edited) I need to sort a 2D array selecting an element someone can help me? ThanksHmm, crystal ball is broke, do you have the 2d array or are we just supposed to write something up ourselves? Edit: Actually, I'll be as informative... If you look at IniReadSection() or IniReadSectionNames() in Beta, that has an example of a 2d array being read. And a description of the elements as well. Edit2: Here's a messed up example of what you can do to choose an element:Local $Array[2][8] $Array[1][6] = 'You clicked Yes On the MsgBox()' $Array[1][7] = 'You clicked No On the MsgBox()' MsgBox(0, 'Example', _PicAnElement($Array, 1, MsgBox(68, 'Question', 'Would you like to continue?'))) Func _PicAnElement(ByRef $aArray, $i_Element1, $i_Element2) Return $aArray[$i_Element1][$i_Element2] EndFunc Edited May 9, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MatteoGuallini Posted May 9, 2006 Author Share Posted May 9, 2006 I'm very sorry. The main problem for me is to search an element in a 2dArray similarly to "_ArrayBinarySearch ". http://www.vigevano-prabis.it/ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 9, 2006 Moderators Share Posted May 9, 2006 I'm very sorry. The main problem for me is to search an element in a 2dArray similarly to "_ArrayBinarySearch ".Don't be sorry just post an example of your issue so you can learn from an actual example of what you are doing Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MatteoGuallini Posted May 9, 2006 Author Share Posted May 9, 2006 This is an example of array i've created. Dim $DayEN2IT[2][7] Dim $DayEN[7] Dim $DayIT[7] $DayEN[0]="Monoday" $DayEN[1]="Tuesday" $DayEN[2]="Wednesday" $DayEN[3]="Thursday" $DayEN[4]="Friday" $DayEN[5]="Saturday" $DayEN[6]="Sunday" $DayEN[0]="Lunedi" $DayIT[1]="Martedi" $DayIT[2]="Mercoledi" $DayIT[3]="Giovedi" $DayIT[4]="Venerdi" $DayIT[5]="Sabato" $DayIT[6]="Domenica" For $I=0 to UBound ($DayEN2IT,2)-1 $DayEN2IT[0][$I]=$DayEN[$I] $DayEN2IT[1][$I]=$DayIT[$I] Next The problem is i can't use "_ArrayBinarySearch" function wit array called "$DayEN2IT" because it is 2d Array. Regarding the example i want to search in the "$DayEN2IT" if there is "Giovedi" and jump to the corresponding english day. http://www.vigevano-prabis.it/ Link to comment Share on other sites More sharing options...
Don N Posted May 9, 2006 Share Posted May 9, 2006 Since this is just a 2 by 7 array why not jsut use parallel arrays adn if u get a "Giovedi" in the first array then go to that index in the second array and that will be the corresdponding english day. _____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper Link to comment Share on other sites More sharing options...
randallc Posted May 9, 2006 Share Posted May 9, 2006 Hi, @Don N is correct; For your example , you could switch it back to single array for the search; use a func like below; $ar_ArrayToSearch=_Array2DToD( $DayEN2IT, "Array contents", 0, 0, 1) _ArrayDelete($ar_ArrayToSearch,0) $i_IndexFound=_ArraySearch($ar_ArrayToSearch,"Wednesday") MsgBox(0,"","$DayEN2IT[1][$i_IndexFound]="&$DayEN2IT[1][$i_IndexFound]) Func _Array2DToD(ByRef $ar_Array, $s_Title = "Array contents", $n_Index = 1, $Line = 0, $s_i_Column = 0) ; Change Line "X" to 1 dimensional array; [Randallc - I have ***lifted it from Forum at some stage]Local $output = "" Local $r, $e, $Swap If $n_Index <> 0 Then $n_Index = 1; otherwise I can't cope! If $s_i_Column <> 0 Then $s_i_Column = 1; otherwise I can't cope! If $Line < 0 Then $Line = 0; otherwise I can't cope! ;If $Line>UBound($ar_Array,1+($s_i_Column=0))+($n_Index=0)-2 then $Line=UBound($ar_Array,)+($n_Index=0)-2 ; otherwise I can't cope! If $Line > UBound($ar_Array, 1+ ($s_i_Column = 0)) + ($n_Index = 0) - 2 Then $Line = UBound($ar_Array, 1+ ($s_i_Column = 0)) + ($n_Index = 0) - 2; otherwise I can't cope! Dim $Array[uBound($ar_Array, 1 + $s_i_Column) + ($n_Index = 0) ] $Array[0] = UBound($ar_Array, 1 + $s_i_Column) + ($n_Index = 0) If Not IsArray($ar_Array) Then Return -1 For $r = $n_Index To UBound($ar_Array, 1 + $s_i_Column) - 1 $e = $r $NewLine = $Line If $s_i_Column = 1 Then $NewLine = $r $e = $Line EndIf $Array[$r+ ($n_Index = 0) ] = $ar_Array[$e][$NewLine] Next ;_ArrayDisplay($Array,$s_Title&"Line"&$Line) Return $Array EndFunc ;==>_Array2DToDBest, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
neogia Posted May 9, 2006 Share Posted May 9, 2006 Since this is just a 2 by 7 array why not jsut use parallel arrays adn if u get a "Giovedi" in the first array then go to that index in the second array and that will be the corresdponding english day.Umm... forgive me if I'm wrong/confused Don N, but isn't a 2d Array just exactly that? 2 parallel arrays of the same length? In any case: expandcollapse popupDim $DayEN2IT[2][7] Dim $DayEN[7] Dim $DayIT[7] $DayEN[0]="Monoday" $DayEN[1]="Tuesday" $DayEN[2]="Wednesday" $DayEN[3]="Thursday" $DayEN[4]="Friday" $DayEN[5]="Saturday" $DayEN[6]="Sunday" $DayIT[0]="Lunedi" $DayIT[1]="Martedi" $DayIT[2]="Mercoledi" $DayIT[3]="Giovedi" $DayIT[4]="Venerdi" $DayIT[5]="Sabato" $DayIT[6]="Domenica" For $I=0 to UBound ($DayEN2IT,2)-1 $DayEN2IT[0][$I]=$DayEN[$I] $DayEN2IT[1][$I]=$DayIT[$I] Next MsgBox(0,"",_CustomArraySearch2d($DayEN2IT, 1, 0, "Venerdi", 0, 1)) Func _CustomArraySearch2d(ByRef $array, $subscriptToSearch, $subscriptToReturn, $searchString, $matchSubString = 1, $caseSensitive = 0) For $i = 0 To UBound($array, 2) - 1 If $matchSubString == 1 Then If $caseSensitive == 0 Then If StringInStr($array[$subscriptToSearch][$i], $searchString) Then If UBound($array, 1)-1 >= $subscriptToReturn Then Return $array[$subscriptToReturn][$i]; Success Else SetError(2); Dimension To Return does not exist in Array Return ""; Failure EndIf EndIf Else If StringInStr($array[$subscriptToSearch][$i], $searchString, 1) Then If UBound($array, 1)-1 >= $subscriptToReturn Then Return $array[$subscriptToReturn][$i]; Success Else SetError(2); Dimension To Return does not exist in Array Return ""; Failure EndIf EndIf EndIf Else If $caseSensitive == 0 Then If $array[$subscriptToSearch][$i] = $searchString Then If UBound($array, 1)-1 >= $subscriptToReturn Then Return $array[$subscriptToReturn][$i]; Success Else SetError(2); Dimension To Return does not exist in Array Return ""; Failure EndIf EndIf Else If $array[$subscriptToSearch][$i] == $searchString Then If UBound($array, 1)-1 >= $subscriptToReturn Then Return $array[$subscriptToReturn][$i]; Success Else SetError(2); Dimension To Return does not exist in Array Return ""; Failure EndIf EndIf EndIf EndIf Next SetError(1); Match Not Found (check $matchSubStrings and $caseSensitive) Return ""; Failure EndFunc Make sure you pay attention to the $caseSensitive and $matchSubString parameters you send to the function. Also, be aware that $subscriptToSearch and $subscriptToReturn are 0-based, as in the example I gave you. [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia Link to comment Share on other sites More sharing options...
Don N Posted May 9, 2006 Share Posted May 9, 2006 Umm... forgive me if I'm wrong/confused Don N, but isn't a 2d Array just exactly that? 2 parallel arrays of the same length Not always, a 2d array could be $array[20][20] or $array[3][100], they are not always a 2 by x array. In this case tho it is simple because the 2d array is 2 by 7 and you can jsut use the two original arrays in parallel and not worry about working with a 2d array. _____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper 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