Jump to content

2D array | vertical wrap around | _ArrayExtract won't get 1st row?


Guy_
 Share

Go to solution Solved by Melba23,

Recommended Posts

If I wanna be able to "vertically rotate" (scroll up and down) 2D array rows, like...

row 0
row 1
row 2

to

row 2
row 0
row 1

etc. (both directions, where the one that disappears goes to the other end) ...

1) Do I have to make my own function, or is there a simple trick I am missing?

2) If I have to make my own function, would it be more or less like this one I made up?
 

Problem here is that only "UP" is working...

* I may be missing something very simple...? :-)

* Why can't I seem to get the first row with _ArrayExtract($_aArray, 0, 0) somehow anyway...?

#include <Array.au3>

HotKeySet("{PGUP}", "_ArrayUp")
HotKeySet("{PGDN}", "_ArrayDown")

Global $aArray[3][2] = [["0 ", " car"],["1 ", " bike"],["2 ", " boat"]]

ToolTip(_ArrayToString($aArray), 0,0)

While 1
    Sleep(100)
WEnd


Func _2D_ArrayScroll_vert ( $_aArray, $direction = 0 )

    Local $aSplit_1, $aSplit_2

    If $direction = 0 Then    ; scroll DOWN
        ; get all rows except last
        $aSplit_1 = _ArrayExtract($_aArray, 0, UBound($_aArray) - 2 )
;~             MsgBox(0,"", _ArrayToString($aSplit_1))
        ; get last row only
        $aSplit_2 = _ArrayExtract($_aArray, UBound($_aArray) - 1, UBound($_aArray) - 1 )
;~             MsgBox(0,"", _ArrayToString($aSplit_2))
        ; $aSplit_2 = 'last row' + 'all rows except last'
        _ArrayAdd($aSplit_2, $aSplit_1)
        $_aArray = $aSplit_2
    Else                    ; scroll UP
        $aSplit_1 = _ArrayExtract($_aArray, 1, UBound($_aArray) - 1 )
            MsgBox(0,"", _ArrayToString($aSplit_1))
; PROBLEM AREA: how to get 1st row of $_aArray into $aSplit_2 ?
;~      $aSplit_2 = $_aArray[0][2]  ; doesn't work  [1][2] neither
        $aSplit_2 = _ArrayExtract($_aArray, 0, 0)  ; doesn't work, other variations get the wrong row, or too many rows
            MsgBox(0,"", _ArrayToString($aSplit_2))
        _ArrayAdd ($aSplit_1, $aSplit_2)
        $_aArray = $aSplit_1
    EndIf

    $aArray = $_aArray

    ToolTip(_ArrayToString($aArray), 0,0)

EndFunc


Func _ArrayDown()
    _2D_ArrayScroll_vert ( $aArray )
EndFunc


Func _ArrayUp()
    _2D_ArrayScroll_vert ( $aArray, -1 )
EndFunc


#cs
; DOWN
0 car
1 bike
2 boat

2 boat
0 car
1 bike

; UP
0 car
1 bike
2 boat

1 bike
2 boat
0 car
#ce

Thanks!  :)

Edited by Guy_
Link to comment
Share on other sites

You can check out this here whether it is what you are looking for: 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

You can check out this here whether it is what you are looking for: 

 

Thanks, but that looks very freaky! ;)  (at 1st sight not too related or too complicated to get into after losing the wole morning already...)

I'm hoping for a simple fix in my code, *or* a simpler way, *and* to know why _ArrayExtract doesn't work for row 0 there...?

Edited by Guy_
Link to comment
Share on other sites

  • Moderators
  • Solution

Guy_,

There was a bug in __ArrayExtract - it has been fixed in the Beta release since July. You can get the latest Beta here. ;)

I would do what you want like this: :)

#include <Array.au3>

HotKeySet("{PGUP}", "_ArrayUp")
HotKeySet("{PGDN}", "_ArrayDown")
HotKeySet("{ESC}", "_Exit")

Global $aArray[3][2] = [["0 ", " A"], ["1 ", " B"], ["2 ", " C"]]

ToolTip(_ArrayToString($aArray), 0, 0)

While 1
    Sleep(10)
WEnd

Func _ArrayUp()
    $aTmp = _ArrayExtract($aArray, 1, Default)        ; Extract all but top row
    _ArrayAdd($aTmp,  _ArrayExtract($aArray, 0, 0))   ; Add top row at bottom
    $aArray = $aTmp
    ToolTip(_ArrayToString($aArray), 0, 0)
EndFunc

Func _ArrayDown()
    $iUBound = UBound($aArray)                                             ; Get size of array
    $aTmp = _ArrayExtract($aArray, 0, $iUBound - 2)                        ; Extract all but last
    _ArrayInsert($aTmp, 0, _ArrayExtract($aArray, $iUBound - 1, Default))  ; Insert last at top
    $aArray = $aTmp
    ToolTip(_ArrayToString($aArray), 0, 0)
EndFunc

Func _Exit()
    Exit
EndFunc
Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The manual way:

#include <Array.au3>

HotKeySet("{PGUP}", "_ArrayUp")
HotKeySet("{PGDN}", "_ArrayDown")
HotKeySet("{ESC}", "_Exit")

Global $aArray[3][2] = [["0 ", " car"],["1 ", " bike"],["2 ", " boat"]]

ToolTip(_ArrayToString($aArray), 0,0)

While 1
    Sleep(100)
WEnd


Func _2D_ArrayScroll_vert ( ByRef $_aArray, $direction = 0 )

    Local $iX, $iY, $iW = UBound($_aArray, 2) - 1, $iH = UBound($_aArray) - 1, $aTmp[$iW + 1]

    If $direction = 0 Then    ; scroll DOWN
        For $iX = 0 To $iW
            $aTmp[$iX] = $_aArray[$iH][$iX]
        Next
        For $iY = $iH To 1 Step - 1
            For $iX = 0 To $iW
                $_aArray[$iY][$iX] = $_aArray[$iY - 1][$iX]
            Next
        Next
        For $iX = 0 To $iW
            $_aArray[0][$iX] = $aTmp[$iX]
        Next
    Else                    ; scroll UP
        For $iX = 0 To $iW
            $aTmp[$iX] = $_aArray[0][$iX]
        Next
        For $iY = 1 To $iH
            For $iX = 0 To $iW
                $_aArray[$iY - 1][$iX] = $_aArray[$iY][$iX]
            Next
        Next
        For $iX = 0 To $iW
            $_aArray[$iH][$iX] = $aTmp[$iX]
        Next
    EndIf

    ToolTip(_ArrayToString($aArray), 0,0)

EndFunc


Func _ArrayDown()
    _2D_ArrayScroll_vert ( $aArray )
EndFunc


Func _ArrayUp()
    _2D_ArrayScroll_vert ( $aArray, -1 )
EndFunc


Func _Exit()
    Exit
EndFunc

#cs
; DOWN
0 car
1 bike
2 boat

2 boat
0 car
1 bike

; UP
0 car
1 bike
2 boat

1 bike
2 boat
0 car
#ce

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

There was a bug in __ArrayExtract. ;)

 

Neat. And yep, that fixed it and made both our versions work. Thanks!

I'm now more confident that I should report what I think is a bug and I'm looking for the bug section already :)

The manual way:

 

You freak me out!  :P

I'm guessing this is code so you don't need the UDF version?

Interesting to see (for code junkies ;) )

Link to comment
Share on other sites

  • Moderators

Guy_,

Good. :)

 

I'm now more confident that I should report what I think is a bug

If there is any doubt as to whether it is a bug, could I suggest posting in the forum first to see if others agree. Then if confirmed you can open a Trac ticket - use the BugTracker link in the menu bar above the forum. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...