Jump to content

_ArrayColInsert


jugador
 Share

Recommended Posts

Slight modification of @Melba23 _ArrayColInsert.

version 1.0 (support)
   > insert single blank row
   > insert 1D Array

 

#include <Array.au3>

Local $o_Eg[6][] = [['A', 11, 22, 33, 44], _
                    ['B', 11, 22, 33, 44], _
                    ['C', 11, 22, 33, 44], _
                    ['D', 11, 22, 33, 44], _
                    ['E', 11, 22, 33, 44], _
                    ['F', 11, 22, 33, 44]]
_ArrayDisplay($o_Eg)

Local $fillArray[6] = ['XX', 'XX', 'XX', 'XX', 'XX', 'XX']
_ArrayDisplay($fillArray)

__ArrayColInsert($o_Eg, 5)
_ArrayDisplay($o_Eg)

__ArrayColInsert($o_Eg, 0)
_ArrayDisplay($o_Eg)

__ArrayColInsert($o_Eg, 0, $fillArray)
_ArrayDisplay($o_Eg)

__ArrayColInsert($o_Eg, UBound($o_Eg, 2), $fillArray)
_ArrayDisplay($o_Eg)


; #FUNCTION# =============================================================================
; Name...........: __ArrayColInsert()
; =========================================================================================
Func __ArrayColInsert(ByRef $aArray, $iColumn = 0, $ArrayFill = '')
    If Not IsArray($aArray) Then Return SetError(1, 0, -1)

    Local $bArray[UBound($aArray, 1)]
    If IsArray($ArrayFill) Then
        If (UBound($aArray, 1) <> UBound($ArrayFill, 1)) Then  Return SetError(1, 0, -1)
        $bArray = $ArrayFill
    Endif

    Local $iDim_1 = UBound($aArray, 1)
    Switch UBound($aArray, 0)
        Case 1
            Local $aTempArray[$iDim_1][2]
            Switch $iColumn
                Case 0, 1
                    For $i = 0 To $iDim_1 - 1
                        $aTempArray[$i][(Not $iColumn)] = $aArray[$i]
                        $aTempArray[$i][$iColumn] = $bArray[$i]
                    Next
                Case Else
                    Return SetError(3, 0, -1)
            EndSwitch
            $aArray = $aTempArray

        Case 2
            Local $iDim_2 = UBound($aArray, 2)
            If $iColumn < 0 Or $iColumn > $iDim_2 Then Return SetError(3, 0, -1)
            ReDim $aArray[$iDim_1][$iDim_2 + 1]
            For $i = 0 To $iDim_1 - 1
                For $j = $iDim_2 To $iColumn + 1 Step -1
                    $aArray[$i][$j] = $aArray[$i][$j - 1]
                Next
                $aArray[$i][$iColumn] = $bArray[$i]
            Next
        Case Else
            Return SetError(2, 0, -1)
    EndSwitch
    Return UBound($aArray, 0)
EndFunc

 

to download Array Insert Column ( version 2.0 )
https://www.autoitscript.com/forum/topic/206264-_arraycolinsert/?do=findComment&comment=1485725

Edited by jugador
Link to comment
Share on other sites

Could you please be so kind and add some documentation to your example scripts?
Why is your code better than the original function?
Is it faster? Does it add functionality? Does it fix a bug? Unfortunately my cristal ball doesn't tell me ;)
 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

In Autoit 3.3.14.5 version (that's what I am using)

; #FUNCTION# ====================================================================================================================
; Author ........: Melba23
; Modified.......:
; ===============================================================================================================================
Func _ArrayColInsert(ByRef $aArray, $iColumn)

So @water you don't need cristal ball to know the difference 😛. Besides example is given just run it ;).

 

Link to comment
Share on other sites

  • Moderators

jugador,

i agree with water. Please do offer some explanations of why you felt the need to create your specific UDF and how it differs from any existing function.

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

@Melba23 now I am confuse 🤔 seeing you asking for explanation
with default _ArrayColInsert you can only insert blank column
but now you can insert blank column and also can insert 1D array (like $fillArray from 1st post)

Local $fillArray[6] = ['XX', 'XX', 'XX', 'XX', 'XX', 'XX']

 

Link to comment
Share on other sites

@jugador  Maybe it is clear for you.  But not everybody remembers exactly all the parameters of all the functions.  This is why it is a good practice to give a bit of an explanation when posting an example.  You will most likely get a larger audience doing so...

Link to comment
Share on other sites

  • Moderators

jugador,

Quote

@Melba23 now I am confuse 🤔 seeing you asking for explanation

As Nine pointed out above, not everyone remembers every parameter for every function. Even though I wrote the current versions of some of your recent _Array* examples I had to go and look at the details in the Help file before I spotted the difference in your versions. Explaining theses differences when you post would help everyone to see why you felt the need to produce slightly different functionalities.

And please do not take this as criticism of the UDFs themselves - if they are good enough we might even add them to the standard library.

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

Don't feel updating 1st post as it complete different code


Array Insert Column ( version 2.0 )
    > insert single / multiple blank row
    > support insertion of 1D & 2D Array

Now do run the code for better explanation ;)

#include <Array.au3>
#include "ArrayInsertCol.au3"

Local $o_Eg[6][] = [['A', 11, 22, 33, 44], _
                    ['B', 11, 22, 33, 44], _
                    ['C', 11, 22, 33, 44], _
                    ['D', 11, 22, 33, 44], _
                    ['E', 11, 22, 33, 44], _
                    ['F', 11, 22, 33, 44]]

Local $fillArray_A[6] = ['PP', 'PP', 'PP', 'PP', 'PP', 'PP']
Local $fillArray_C[6][] = [['AA', 'BB'], ['AA', 'BB'], ['AA', 'BB'], ['AA', 'BB'], ['AA', 'BB'], ['AA', 'BB']]

;__ArrayColInsert_V2($o_Eg, 1, '', 4)
__ArrayColInsert_V2($o_Eg, 0, '', 6)

;__ArrayColInsert_V2($o_Eg, 0, $fillArray_A)
;__ArrayColInsert_V2($o_Eg, 1, $fillArray_A)
;__ArrayColInsert_V2($o_Eg, UBound($o_Eg, 2), $fillArray_A)

;__ArrayColInsert_V2($o_Eg, 0, $fillArray_C)
;__ArrayColInsert_V2($o_Eg, 1, $fillArray_C)
;__ArrayColInsert_V2($o_Eg, UBound($o_Eg, 2), $fillArray_C)
_ArrayDisplay($o_Eg)


;__ArrayColInsert_V2($fillArray_A, 1, '', 2)
;__ArrayColInsert_V2($fillArray_A, 0, '', 4)

;__ArrayColInsert_V2($fillArray_A, 0, $fillArray_C)
;__ArrayColInsert_V2($fillArray_A, 1, $fillArray_C)
;_ArrayDisplay($fillArray_A)

 

__ArrayColInsert_V2 UDF

ArrayInsertCol.au3

Edited by jugador
Link to comment
Share on other sites

  • 5 weeks later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...