Jump to content
Sign in to follow this  
Zopieux

Questions about arrays

Recommended Posts

Zopieux

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 :)

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Zopieux

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


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

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
Zopieux

Many thanks, I am going to test it right now.


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

Share this post


Link to post
Share on other sites
Zopieux

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 :)

Share this post


Link to post
Share on other sites
randallc

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

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
Zopieux

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 :)

Share this post


Link to post
Share on other sites
weaponx

What are the original dimensions for your array? Show me the code that declares $Rep

EDIT: I reposted the function. Did you try the new code?

Edited by weaponx

Share this post


Link to post
Share on other sites
Zopieux

Ok, I have just edited my message. Can you take a look at it :) ?


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

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
Zopieux

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 :)

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
Zopieux

Ok, many thanks, problems are resolved :) !

Best regards.


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

Share this post


Link to post
Share on other sites
randallc

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

Share this post


Link to post
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
Sign in to follow this  

×