Jump to content

Questions about arrays


Zopieux
 Share

Recommended Posts

Hi all,

I have two little interrogations.

First, how to declare a 2 dimensional array without size limit.

E.g. : Dim $array[][2] (but of course it is not working)

Then, I tested the _ArrayAdd function with a 2 dimensional array but it is not working : the func doesn't support it ?

I want to insert "Bar" in the second dimension of $foo[] with the fonction _ArrayAdd for instance. How can I do it ?

Thank in advance ! :)

Best regards,

Zopieux

I'm not English, then please excuse my spelling :)

Link to comment
Share on other sites

  • Developers

Hi all,

I have two little interrogations.

First, how to declare a 2 dimensional array without size limit.

E.g. : Dim $array[][2] (but of course it is not working)

Then, I tested the _ArrayAdd function with a 2 dimensional array but it is not working : the func doesn't support it ?

I want to insert "Bar" in the second dimension of $foo[] with the fonction _ArrayAdd for instance. How can I do it ?

Thank in advance ! :)

Best regards,

Zopieux

You need to set the size... You can always increase it with a redim ....

;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Ok, thanks. But what about the second problem ? ;)

just write your own function .... _ArrayAdd() only works on single dimed arrays...

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Dim $array[4][2] = [["John", "Smith"],["Steven", "Tyler"],["Jean", "Grey"],["Abe","Lincoln"]]

_ArrayDisplay($array)

_ArrayAddX($array, "Dan", "Marino")

_ArrayDisplay($array)

Func _ArrayAddX(ByRef $myA, $value1, $value2)
    Redim $myA[Ubound($array) + 1][Ubound($myA, 2)]
    $myA[Ubound($array) - 1][0] = $value1
    $myA[Ubound($array) - 1][1] = $value2
EndFunc

EDIT: This is for 2 dimensions only. Beyond 2 dimensions you have to pass an array to the function and it just looks messy.

Edited by weaponx
Link to comment
Share on other sites

Ok, there is a problem : the debug says :

C:\...\file.au3 (142) : ==> Variable used without being declared.:

Redim $myA[ubound($array) + 1][ubound($myA, 2)]

The function is placed at the end of the code.

What have I to do ?

I'm not English, then please excuse my spelling :)

Link to comment
Share on other sites

Ok, there is a problem : the debug says :

The function is placed at the end of the code.

What have I to do ?

Hi,

Easiest to get help if you post your script; either add it to your post ["Browse","Upload"], or put it in "AutoIt" message box in edit (under combobox with "Insert Special Item")

Best, randall

Link to comment
Share on other sites

Well it tested okay for me but I forgot I changed up some of the variable names.

#include <array.au3>

Dim $array[4][2] = [["John", "Smith"],["Steven", "Tyler"],["Jean", "Grey"],["Abe","Lincoln"]]

_ArrayDisplay($array)

_ArrayAddX($array, "Dan", "Marino")

_ArrayDisplay($array)

Func _ArrayAddX(ByRef $myA, $value1, $value2)
    Redim $myA[Ubound($myA) + 1][Ubound($myA, 2)]
    $myA[Ubound($myA) - 1][0] = $value1
    $myA[Ubound($myA) - 1][1] = $value2
EndFunc
Link to comment
Share on other sites

EDIT: ok, weaponx, it is now working, but your function adds the entry at the end of the array, even if there is nothing before...

Is it possible to change something/create a new function which fixes the problem ?

Edited by Zopieux

I'm not English, then please excuse my spelling :)

Link to comment
Share on other sites

The whole purpose of this is that it lets you declare a 1x2 array and it will redimension it for you. I believe _ArrayAdd would do the same thing for a one-dimensional array.

Edited by weaponx
Link to comment
Share on other sites

Fine, I will declare the littlest array I can.

But there is another problem (I hate arrays :) ) : I will need a function to remove an entry of this 2 dimensional array. Is it possible ? I wonder if _ArrayDelete can work on a 2 dimensional array...

I'm not English, then please excuse my spelling :)

Link to comment
Share on other sites

Dim $array will resize AND delete its contents.

Redim $array will only resize.

So you if you had an array like:

Dim $array[40][2]

Redim $array[45][2] would make it larger

Dim $array[40][2] would flush it

Link to comment
Share on other sites

Fine, I will declare the littlest array I can.

But there is another problem (I hate arrays :) ) : I will need a function to remove an entry of this 2 dimensional array. Is it possible ? I wonder if _ArrayDelete can work on a 2 dimensional array...

Hi,

You can use 'Array2D.au3" from my sig, which has Arraydel2D, ArrayInsert2D ets pre-written; or write your own.

I was using large arrays, so converted the UDF to use Scriptcontrol vbs for speed, but originally they were in AutoIt; can find it somewhere if you want.

Best, randall

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...