Jump to content

[Solved]_How to add columns to an Array ?


Recommended Posts

Array with 1 column is pretty useless, how can I add more columns hire like: _ArrayAdd($avArray, $e,$e) ?

Dim $avArray[1]

 For $e = 1 to 100
    _ArrayAdd($avArray, $e)
Next

_ArrayDisplay($avArray, " 2nd added")
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

The distinction is entirely arbitrary, but most people use the spreadsheet paradigm and refer to the index in the first dimension as "row" and the second dimension as "columns". The _ArrayAdd() UDF is single dimension only, so wouldn't be used with 2D arrays. You can change the size, including the number of dimensions, with ReDim but if you change the number of dimensions, previous contents of the array are lost.

If you already know how many columns you need, just declare that initially, but the change can be done dynamically:

#include <Array.au3>

Global $avArray[1] = [0]

For $e = 1 To 10
    $iRow = UBound($avArray)
    $iCol = UBound($avArray, 2)
    ReDim $avArray[$iRow + 1][$iCol + 1]
    For $n = 0 To $iCol
        $avArray[$iRow][$n] = $e ^ $n
    Next
    $avArray[0][0] = UBound($avArray) - 1
    _ArrayDisplay($avArray, "$avArray")
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is what I was looking for, Thanx.

#include <Array.au3>

;~ =====================================
Dim $avArray[11][4]  ; 11 Rows & 4 Columns at the beginning (Cuz I know how many Rows I need)

For $n = 1 To 10
    $avArray[$n][0] = $n
    $avArray[$n][1] = $n
Next
 _ArrayDisplay($avArray, "$avArray")
 
;~ =====================================

Dim $avArray[1][4] ;1 Row & 4 columns at the beginning ; Hire we are adding more rows

For $x = 1 To 10
    $iRow = UBound($avArray)    ;add Rows
    $iCol = UBound($avArray, 2) ;Add Columns
    
    ReDim $avArray[$iRow + 1][$iCol]    ; add more rows +1
     
    $avArray[$x][0] = $x
    $avArray[$x][1] = $x
Next
 _ArrayDisplay($avArray, "$avArray")
;~ =====================================

Exit
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
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

  • Recently Browsing   0 members

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