Jump to content

How to create unknown array size ?


pinkfoyd
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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?

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.

Link to comment
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.

Link to comment
Share on other sites

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.

 

Link to comment
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!

Link to comment
Share on other sites

  • Developers

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.

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

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