ich hab das ganze mal umgesetzt, so wie ich es verstanden habe. Am Ende besteht nur das Problem, dass die letzten Werte nicht zugeordnet werden können, da das Positions-Array kein Vielfaches vom Value-Array ist...
Es geht sich also am Ende nicht aus, oder man hätte leere Zellen. In der Lösung wird das Ende erstmal weggelassen, ggf. kannst du ja klarstellen, was dann passieren soll.
Außerdem: Position <> Index? Bei mir sind die Einträge einen Wert höher, weil man beim Programmieren mit 0 anfängt, nicht mit 1.
#include <Array.au3>
Global $arValues = ["DK45","DK28","963","NOR17","731","575","276","679","366","NOR15","NOR58","NOR23","958","166","909","478","634","846","744","525","701","77","162","211","51DK","873","401", _
"909","717","52","552","707","327","782","705","644","47","524","596","NOR88","246","700","197","696","497","913","35","99","DK42","725","652","584","701","36","296","402", _
"483","961","NOR87","9","482","944","613","161","205","657","734","329","791","750","731","196","437","312","979","489","NOR55","787","39","FIN01","764","344","745","666", _
"733","37","273","38","784","797","109","903","340","272","742","426","127","206","623","842","DK45","DK28","963","NOR17","731","575","276","679","366","NOR15","NOR58", _
"NOR23","958","166","909","478","634","846","744","525","701","77","162","211","51DK","873","401","909","717","52","552","707","327","782","705","644","47","524","596", _
"NOR88","246","700","197","696","497","913","35","99","DK42","725","652","584","701","36","296","402","483","961","NOR87","9","482","944","613","161","205","657","734", _
"329","791","750","731","196","437","312","979","489","NOR55","787","39","FIN01","764","344","745","666","733","37","273","38","784","797","109","903","340","272","742", _
"426","127","206","623","842","39","954","99NOR","FIN2","388"]
Global $iPosBegin = 55
;,Reihenfolge,64,Werte
Global $arPositions = [55,30,17,42,27,36,15,38,18,43,54,29,16,39,26,35,31,56,41,20,33,28,37,14,44,19,32,53,40,13,34,25,57,2,45,8,21,64,51,12,46,5,60,1,52,9,24,63,3,58,7,48,61,22,11,50,6,47, _
4,59,10,49,62,23]
Local $arRes = _sortByArray($arValues, $arPositions, $iPosBegin)
If @error Then MsgBox(16,"Error",@error&" => "&@extended)
_ArrayDisplay($arRes)
; $arValues => Values to sort
; $arPos => Positions to sort to
; $iStartValue => First position to start with; Default => Start with $arPos index 0; If $iStartValue is not in $arPos => Start with $arPos index 0; Starts with the first position found
Func _sortByArray(ByRef $arValues, ByRef $arPos, $iStartValue = Default)
Local $iStartIndex = 0
If $iStartValue<>Default Then
For $i=0 To UBound($arPos)-1 Step 1
If $iStartValue=$arPos[$i] Then
$iStartIndex = $i
ExitLoop
EndIf
Next
EndIf
Local $iIndex = $iStartIndex
Local $iPosCount = UBound($arPos)
Local $arResult[UBound($arValues)]
Local $iPassCount = 0
For $i=0 To UBound($arValues)-1 Step 1
Local $iTmpIndex = $iPassCount*$iPosCount+$arPos[$iIndex] - 1 ; -1 because positions in $arPos start with 1 and not 0
If $iTmpIndex>=UBound($arValues) Or $iTmpIndex<0 Then
;Return SetError(1, $iTmpIndex, -1) ; check if new index is in range
Else
$arResult[$iTmpIndex] = $arValues[$i]
EndIf
$iIndex+=1
If $iIndex>=UBound($arPos) Then $iIndex=0
If $iIndex=$iStartIndex Then $iPassCount+=1
Next
Return $arResult
EndFunc
Alles anzeigen