Sign in to follow this  
Followers 0
pinkfoyd

How to create unknown array size ?

9 posts in this topic

hi all !

can someone can help me explan why i can do this :

dim $test

$test[0] = 1

that return :

test.au3 (2) : ==> Badly formated variable or macro.:

$test[0] = 1

$test^ ERROR

because i don't like create a very large array ( ie : dim $test[999] )

they are no solution for create a dynamicaly extentable array ?

hope my explanation was clear :o

Share this post


Link to post
Share on other sites



hi all !

can someone can help me explan why i can do this :

dim $test

$test[0] = 1

that return :

test.au3 (2) : ==> Badly formated variable or macro.:

$test[0] = 1

$test^ ERROR

because i don't like create a very large array ( ie : dim $test[999] )

they are no solution for create a dynamicaly extentable array ?

hope my explanation was clear :o

Have a script to look at?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Probably because you are not creating $test as an array to start with, then trying to access it as an array.

I think that I usually _ArrayCreate.

i.e. (untested)

dim $test = _ArrayCreate ( 1 )

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Have a script to look at?

Dim $test
;do some code
If Not IsArray($test) Then
   Dim $test[1]
Else
  ReDim $test[Ubound($test) + 1]
EndIf
$test[Ubound($test) - 1] = 1
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ok grafost,

as i understand, the only solution is to do a resize of the array for each element i need to insert..

thanks !

Edited by pinkfoyd

Share this post


Link to post
Share on other sites

Hi!

I am not sure about the last post. How do you resize an array?

If what I think is you mean to do is

$test = _ArrayCreate ( 1 )

;later wen I need to resize
$test = _ArrayCreate ( 2 )

Will resizing an array everytime reset it's variable?

That is to say, if I have created an array of size 1 having a value say "name" and then I resize it to 2 as shown above, will the value of array[1] still be "name"?


I believe we should all pay our tax with a smile. I tried - but they wanted cash!

Share this post


Link to post
Share on other sites

Will resizing an array everytime reset it's variable?

That is to say, if I have created an array of size 1 having a value say "name" and then I resize it to 2 as shown above, will the value of array[1] still be "name"?

Remarks

The ReDim keyword is similar to Dim, except that ReDim preserves the values in the array instead of removing the values while resizing an array. The number of dimensions must remain the same, or the old array will be forgotten during the ReDim. The array will retain the scope (Global or Local) that it had prior to resizing.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Yeah...got it!

Thanx ChrisL and JdeB for the infos.

This seems to be a nice feature...gonna experiment with it more.


I believe we should all pay our tax with a smile. I tried - but they wanted cash!

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  
Followers 0