Jump to content

Recommended Posts

Posted (edited)

Hi all,

How to add 2 elements to a 2D array. This is my code, But not working.

Local $ResArray[0][1]   ; Declaring an empty array
Local $Elem1 = 10
Local $Elem2 = 20
_ArrayAdd($ResArray, $Elem1, 0) ; Trying to add first column
_ArrayAdd($ResArray, $Elem2, 1) ; Trying to add second column

_ArrayDisplay($ResArray)

This will only add the first element. 

Edited by kcvinu
  Reveal hidden contents

 

Posted

if you want to add a value to column 2 you should at least declare an array wit 2 columns....

try

Local $ResArray[0][2]

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

  • Moderators
Posted

kcvinu,

You have only 1 column in your 2d array, so how do you expect the function add an element in the a non-existent column?  Had you checked the @error return from the second call to _ArrayAdd (4 - $iStart outside array bounds) you would have discovered this in less time that it took to post.

#include <Array.au3>

Local $ResArray[0][2] ;  2 column array
Local $Elem1 = 10
Local $Elem2 = 20
_ArrayAdd($ResArray, $Elem1, 0)
_ArrayAdd($ResArray, $Elem2, 1)

_ArrayDisplay($ResArray)

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:

  Reveal hidden contents

 

Posted (edited)

Thanks But this was eating my head. 

Sorry to say. This not what i want.

 

000108.jpg

I want 10 & 20 in one row.

Edited by kcvinu
  Reveal hidden contents

 

Posted (edited)

_000109.thumb.jpg.ed76dd5b7db593b323b7d8At last this worked

Local $ResArray[0][2]
Local $Elem1 = 10
Local $Elem2 = 20
Local $temp = $Elem1 & "," & $Elem2

_ArrayAdd($ResArray, $temp, 0,",")

_ArrayDisplay($ResArray)

Is there any other way to do this

 

000109.jpg

Edited by kcvinu
  Reveal hidden contents

 

Posted

@mikell , Short form of my code. You will benefit one line and an extra variable.  :)

  Reveal hidden contents

 

  • Moderators
Posted

kcvinu,

Or just use the default delimiter:

#include <Array.au3>

Local $ResArray[0][2] ;  2 column array
Local $Elem1 = 10
Local $Elem2 = 20
_ArrayAdd($ResArray, $Elem1 & "|" & $Elem2)

_ArrayDisplay($ResArray)

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:

  Reveal hidden contents

 

Posted

@Melba23 Thanks.

@Chimp , Actually, that is not what i wanted. I need to populate a 2D array with this ArrayAdd function.

  Reveal hidden contents

 

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
×
×
  • Create New...