Modify

Opened 13 years ago

Closed 13 years ago

#1964 closed Bug (Completed)

can't make zero-length array, array functions messed up

Reported by: jmichae3@… Owned by:
Milestone: Component: AutoIt
Version: 3.3.6.1 Severity: None
Keywords: Cc:

Description

http://www.autoitscript.com/autoit3/docs/keywords/Dim.htm

I tried
dim $array[0]
"Array subscript variable badly formatted"

this OUGHT to work to make an empty array, and should not be a foreign concept, especially since we have _ArrayAdd and _Array_Delete

so I tried
$array=0
_ArrayAdd($array,"abc")
_ArrayDisplay($array)
however, when I try to do _Array_Add it does not add the string. when I do _ArrayDisplay the array display window does not pop up. your arrays (or documentation) are totally messed up.

more evidence that something is wrong:
dim $array[1]
_ArrayAdd($array,"abc")
_ArrayAdd($array,"def")
_ArrayAdd($array,"ghi")
_ArrayDisplay($array)
$s=_ArrayToString($array, ",")
msgbox(0,"result: there should be no leading comma, but there is", $s)
the result is
,abc,def,ghi

workaround:
dim $array[1] ;define supposedly empty array
$array=0 ;undefine array
dim $array[1] ;redefine supposedly empty array
_ArrayAdd($array,"abc")
_ArrayAdd($array,"def")
_ArrayAdd($array,"ghi")
_ArrayDisplay($array)
$s=_ArrayToString($array, ",", 1) ;avoid the problem of the default zero index
msgbox(0,"result", $s)

please post this in the manual (you can tweak the comments if you like) - and could you have an array section of the manual please? arrays are very important, they are a data type too. I don't know why they are missing from the data types in the docs.

I need something that's the equivalent of a C++ vector or list right now. I think that's what you were almost trying to achieve (what you have also works as a queue or stack, but note that these also must start at *empty*). it should be something that can start at *empty* (like for keeping track of the contents of a combo box or list box control) and I can find out the size of at any time, and
states that to make a zero-length array, you simply assign

some of your array functions by default treat arrays as if they can have a starting index of 0. this is incorrect. my best understanding is that arrays are 1-based, and that index 0 is used as the array size, but in my case I am finding that index 0 is entirely blank when I use _Array_Add(). maybe it's to show that the array index *can* be 0, though it should be 1. unfortunately, the default is 0. _ArrayBinarySearch, _ArrayConcatenate, _ArrayDisplay (iTranspose), _ArrayFindAll, ArraySearch, _ArrayMax, _ArrayMaxIndex, _ArrayMin, _ArrayMinIndex, _ArrayReverse, _ArraySort, _ArrayToClip, _ArrayToString, _ArrayTrim, _ArrayUnique (please decide on whether arrays are 0 or 1-based and make all your functions work accordingly! it's making my programs not work! and please be wise)

Attachments (0)

Change History (6)

comment:1 in reply to: ↑ description Changed 13 years ago by mvg

@OP: AutoIt feature.

@Dev: Doc(bug)(+3.3.7.10) not clear about "[subscript 1]" needing to be "1 to n-1" instead of the "0 to n-1" (valid for consecutive subscript's but not for first.).

comment:2 follow-up: Changed 13 years ago by Valik

I'm pretty sure this ticket is about the wrong thing. AutoIt arrays start at 0. If a function or set of functions choose to use a convention where element 0 is reserved to store the size of the array then that is their business. That does not meant all AutoIt arrays are 1-based or that all arrays have their size stored in element 0.

Regarding _ArrayAdd(), I would fully expect to see a line of code similar to the following in _ArrayAdd():

If Not UBound($array) Then Dim $array[1]

If it does not do that then it needs to because that is logical behavior. I'm leaving this ticket open solely because _ArrayAdd() does not behave in a sensible manner. The rest of the comments prior to this are rubbish and address the wrong thing.

comment:3 Changed 13 years ago by Stilez

Looking only at the issue of zero length arrays, I hit this problem as well. There ought to be a way to create a zero size array, so that elements can be added programmatically using _ArrayAdd(). If you can (in 3.3.6.1) create a zero length array then the Help should say how, if not then a workaround should be in the help for that function.

Valik's idea might work.

comment:4 in reply to: ↑ 2 ; follow-up: Changed 13 years ago by mvg

Replying to Valik:

The rest of the comments prior to this are rubbish and address the wrong thing.

To what comment(s) are you revering to. I only see one.

If its just my comment. Well ... No surprise there of course.

I'm pretty sure this ticket is about the wrong thing.

Aha. No wonder I might have addressed the wrong thing than.

comment:5 in reply to: ↑ 4 Changed 13 years ago by Valik

Replying to mvg:

To what comment(s) are you revering to. I only see one.

Your comment and the ticket creator's comment.

All this talk about 0-length arrays is dumb. Far too much stock is being put in having a magical bit flipped behind the scenes but it offers exactly no functionality improvements. If the suggested 0-length arrays are allowed then the exact same code I demonstrate in comment:3 still has to be written (and indeed would work completely unchanged).

All this boils down to is one or more _Array functions were poorly written and don't handle a very common and very obvious situation. No complex solutions need implemented in AutoIt. The function(s) need fixed to accept non-array variables and to turn them into arrays if that behavior makes sense. No more, no less.

Now please stop with all these useless comments addressing the wrong issue.

comment:6 Changed 13 years ago by trancexx

  • Resolution set to Completed
  • Status changed from new to closed

I didn't saw this ticket earlier.
Anyway, zero size arrays are added in the meantime.
Next version of AutoIt has them. If _Array functions wouldn't be able to support them then make new report.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.