czardas Posted December 19, 2010 Share Posted December 19, 2010 (edited) Please Note : Many of the functions in this thread have been organised into several UDFs found at the following linkDetails of the changes are still being documented.Index1. 2. 3. 4. ?do=embed' frameborder='0' data-embedContent>5..?do=embed' frameborder='0' data-embedContent> - No longer supported6. - Addresses issues with window commands when a disabled control has focus7. 8. 9. 10. - Error handling within Nested Functions11. - Fun but not particularly useful12. - Less fun, but more useful13. 14. 15. - Random bitwise splitting functions.16. - Camel Case conversion has some limited potential use.17. 18. 19. This thread is has been updated several times and is under constant revision. Some of the older entries contain code that has been superseded by more recent versions. Outdated code has been placed inside spoilers to preserve the integrity of the thread.Original first postModular Array Rotation See post number 30 for an improved version.Much of my code involves modular functions. I have previously rotated modular array data in a slow and inefficient way, using far too many ReDims. I have tried to find the best solution, but I would like to hear your opinions. The following code rotates a one dimensional array, as if the first and last element were adjacent to each other in a continuous modular loop.expandcollapse popup#include <Array.au3> ; $av_4rray - One dimensional array to spin. ; $iClix - Clicks must be a positive integer. ; $iMde - Mode set to 0 or 1 indicating the rotation direction. Func _ArrayModularSpin(ByRef $av_4rray, $iClix, $iMde) If IsArray($av_4rray) = 0 Or UBound($av_4rray, 2) Then SetError(1) ElseIf ($iClix < 0) Or (IsInt($iClix) = 0) Then SetError(2) EndIf If @error Then Return If $iClix >= UBound($av_4rray) Then $iClix = Mod($iClix, UBound($av_4rray)) If $iClix = 0 Then Return $av_4rray If $iMde = 0 Then ; Forward rotation. Elements move down. Local $i5plit = $iClix, $iLments = UBound($av_4rray) -$iClix ElseIf $iMde = 1 Then ; Reverse Rotation. Elements move up. Local $i5plit = UBound($av_4rray) -$iClix, $iLments = $iClix Else SetError(3) Return EndIf Local $av_Arrai[$i5plit] For $i1nt = 0 To UBound($av_Arrai) -1 $av_Arrai[$i1nt] = $av_4rray[$iLments +$i1nt] Next ReDim $av_4rray[$iLments] _ArrayConcatenate($av_Arrai, $av_4rray) $av_4rray = $av_Arrai EndFunc ; ============================================================ ; Example 1 Local $asDays = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] _ArrayModularSpin($asDays, 11, 0) _ArrayDisplay($asDays) _ArrayModularSpin($asDays, 4, 1) _ArrayDisplay($asDays) ; ============================================================ ; Example 2 => error test Local $asMessage $asMessage = "The first parameter is not a one dimensional array!" $asMessage = "Incorrect click value!" $asMessage = "Incorrect mode value!" _ArrayModularSpin($asDays, "a", 0) If @error Then MsgBox(0, "Error", $asMessage[@error])Apologies for the strange variable names. I wanted to avoid accidentally repeating them outside the function. You can alter them to suit your needs. For practical purposes: the error checks can be removed, providing that you can guarantee valid parameters will always be passed to the function. Valid parameters are defined in the inline comments above.Func _ArrayModularSpin(ByRef $av_4rray, $iClix, $iMde) If $iClix >= UBound($av_4rray) Then $iClix = Mod($iClix, UBound($av_4rray)) If $iClix = 0 Then Return $av_4rray If $iMde = 0 Then Local $i5plit = $iClix, $iLments = UBound($av_4rray) -$iClix Else Local $i5plit = UBound($av_4rray) -$iClix, $iLments = $iClix EndIf Local $av_Arrai[$i5plit] For $i1nt = 0 To UBound($av_Arrai) -1 $av_Arrai[$i1nt] = $av_4rray[$iLments +$i1nt] Next ReDim $av_4rray[$iLments] _ArrayConcatenate($av_Arrai, $av_4rray) $av_4rray = $av_Arrai EndFunc Edited April 24, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
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 account
Already have an account? Sign in here.Sign In Now