This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X

# Array declaration

38 replies to this topic

### #21 Matt @ MPCS

Matt @ MPCS

Just another AutoIt user trying to help out! :)

• Active Members
• 700 posts

Posted 03 November 2004 - 11:26 PM

Maybe someone can explain to me why an array being 'numeric' is a problem when all conversion is done automatically and all variables are of a variant data type. What is the significance here?

*** Matt @ MPCS

### #22 Angel

Angel

Universalist

• Active Members
• 352 posts

Posted 03 November 2004 - 11:38 PM

You mean that if I have \$x="5" and \$y="7" and I do \$x + \$y I will get 7, right? If that is the case, and all math is handled properly than is less of a problem than I thought.

However, there is still the problem of multidimensional arrays.

Cheers,

Angel

Maybe someone can explain to me why an array being 'numeric' is a problem when all conversion is done automatically and all variables are of a variant data type. What is the significance here?

*** Matt @ MPCS

<{POST_SNAPBACK}>

### #23 Matt @ MPCS

Matt @ MPCS

Just another AutoIt user trying to help out! :)

• Active Members
• 700 posts

Posted 03 November 2004 - 11:41 PM

You mean that if I have \$x="5" and \$y="7" and I do \$x + \$y I will get 7, right?

Well if you do recieve 7 then we have a problem, the correct response (and the one you recieve) is 12.

Proof of concept:
```\$x="5"
\$y="7"
msgbox(0,"",\$x+\$y)```

I bet you won't recieve 7!

I take it you would now back their suggestion for SplitString with multiple delimeters for multiple dimensions?

*** Matt @ MPCS

Edited by Matt @ MPCS, 03 November 2004 - 11:58 PM.

### #24 Angel

Angel

Universalist

• Active Members
• 352 posts

Posted 04 November 2004 - 08:06 AM

Jaja! That's true, I'm sorry! It is no good writing in a forum after 13 hours at work! I might need to get back to 1st grade, though!

But as you say, I do not thing that using SplitString would be a very good solution. At least it would not be a very elegant one, nor an easy to "explain" or justify to newbies.

I think that either the syntax I proposed or the more C-like syntax proposed by john925 would be the best solution.

Cheers,

Angel

### #25 Nutster

Nutster

Developer at Large

• Developers
• 1,450 posts

Posted 04 November 2004 - 04:10 PM

Correct..
The TODO list is a sticky at the top of the developers forum.
This is in it for stringsplit: StringSplit() full string delimiter option

<{POST_SNAPBACK}>

I have completed that (StringSplit() full string delimiter option). I just have to get around to submitting it. It gets submitted at the same time as RegExp, which is being a bugger!

As far as the main thought of this thread, I would like to work on it after I finish RegExp. My idea would be as follows.
```Dim \$MyArray[][] = [[3, "hello", 8.1], [9,77, "5.5", @year, \$value]]
Dim \$NextArray[5][2][12] = [[[1, 4, 7, 9], [2,3,4]],[["Why", "not", "words", '?']]]```

The first one would figure out how big the array needs to be to store everything and then assign to the array. The second one creates the array and then assigns the values into the corresponding elements. Elements not assigned would be internally NULL (what happens now). I think I know how to do that. It is just a matter of getting the time to do it. What do people think of that?

David Nuttall

Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius
AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

AutoIt lover

• Active Members
• 2,383 posts

Posted 04 November 2004 - 04:17 PM

1. The array assigments should definitely be on one line.
2. I would like to dynamically create arrays. Currently it's easy, but makes me wonder how it would be possible with the syntax Nutster showed us...

### #27 Angel

Angel

Universalist

• Active Members
• 352 posts

Posted 04 November 2004 - 06:37 PM

Nutser, that is really good! Specially the possibility of not setting the size of the array in advance. That is great! You're the !

With your syntax, would it be possible to extract a substring? For instance, using your example, would it be possible to do the following?:

```Dim \$MyArray[][] = [[3, "hello", 8.1], [9,77, "5.5", @year, \$value]]
Dim \$v_dim1
\$v_dim1 = \$MyArray[1]```

and then get [3, "hello", 8.1] in \$v_dim1?

Also, let me be greedy for a moment and ask for something extra ...

I wonder if it would be also possible to easily select array subsets.

For instance, yesterday I had an array of 6 elements and I wanted to remove the 1st and the last element. In AutoIt I had to write a For loop to do this seemingly simple thing, which is ok but quite verbose.

On the other hand, in Matlab it is very easy to do that using the following syntax:

In Matlab: v_small = v_big[2:5] (i.e. puts elements 2 to 5 in array v_small. Note that in Matlab the 1st index is 1 instead of 0 but that is not important for the discussion)

I think that in Java 5 they've added a similar thing. You can do:
v_small = v_big[1..4] and you get the elements 2 to 5 into v_small.

This would be very useful when using the function StringSplit, when you want to remove the 1st element which is the number of elements and you simply want to get the splitted elements.

I know this might be asking too much. I don't want to bloat AutoIt and I don't want to "matlabtify" it either. I like it a lot as it is. But Matlab (and also Java) has some very nice syntax for arrays and it'd be cool if some of them would be added to AutoIt as long as they made sense :-) It is the first time that I have "access" to the developpers of a language and it is very tempting to ask you for these kind of improvements...

I am already very happy with your suggested init syntax though! Thanks!!!! Anything else would be an extra!

Cheers,

Angel

### #28 Angel

Angel

Universalist

• Active Members
• 352 posts

Posted 04 November 2004 - 06:39 PM

1. The array assigments should definitely be on one line.
2. I would like to dynamically create arrays. Currently it's easy, but makes me wonder how it would be possible with the syntax Nutster showed us...

<{POST_SNAPBACK}>

SlimShady, what do you mean with #2? Are you talking about ReDim?

### #29 Nutster

Nutster

Developer at Large

• Developers
• 1,450 posts

Posted 04 November 2004 - 06:52 PM

I am not restricting the current functionality, just adding to it. You would still be able to do dynamic creation using StringSplit. So that will not be removed, just another mechanism gets added.

Oh, I get it now. You want to be able to dynamically create a multi-dimensional array using a beefed-up version of StringSplit. How about: StringRowSplit(\$string, \$ColumnDelim, \$RowDelim [, flag])
\$ColumnDelim defaults to ","
\$RowDelim default to @CRLF. If it is "", then it does not split rows. 1 row only.
Flag defaults to 0. Flag indicates whether the delimters are considered seperatly, that is any character in the delimter breaks the field (0) or as a group (1 for columns, 2 for rows, 3 for both) This version would not put the size of the created array in element 0. The first row would be in row 0 of the array. The first column would be in column 0 of the array. I have already added the flag. Adding the rest shouldn't be that hard.

As for the other stuff, hmm, let's see. How about ArrayExtract which would take the elements indicated and create a new array. ArrayExtract(\$Array, \$dim1Start, \$dim1end {,\$start, \$end}). Repeat \$start, \$end for each element to be extracted. If \$start = \$end then do not create a dimension for that. e.g. \$x = ArrayExtract(\$BigArray, 7,7, 2, 8, 0,5) would create a 7X6 array from the 12X10X6 \$BigArray. \$BigArray[7][2][0] would end up in \$x[0][0]. This may take some time to create.

Edit: Fix math mistake.

Edited by Nutster, 05 November 2004 - 05:00 PM.

David Nuttall

Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius
AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

AutoIt lover

• Active Members
• 2,383 posts

Posted 04 November 2004 - 09:27 PM

I meant assigning values to an array.
I thought Nutster wanted to replace the current syntax:
```Dim \$SampleArray[3][2]
For \$x = 0 To 2
For \$y = 0 To 1
\$SampleArray[\$x][\$y] = "whatever value"
Next
Next```

I am not restricting the current functionality, just adding to it.

Y'know what would be great? A function that can take unlimited parameters that are arrays, and make one multidimensional array.
I made a UDF that does something like that. Called it MergeToArray.
It takes 2 arrays atm, because we can't create functions with unlimited arguments.

### #31 john925

john925

Wayfarer

• Active Members
• 53 posts

Posted 05 November 2004 - 03:31 PM

I really like your proposed syntax, Nutster! I hope we get to see it in place soon.

john925

### #32 Nutster

Nutster

Developer at Large

• Developers
• 1,450 posts

Posted 05 November 2004 - 05:04 PM

I would also be looking at adding ArraySum, ArrayMult, ArrayExtract. I have written ArrayJoin that concatinates a single-dimensioned array into a single string. Yeah, I could add a second delimiter for 2-dimensional arrays.

David Nuttall

Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius
AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

### #33 Angel

Angel

Universalist

• Active Members
• 352 posts

Posted 05 November 2004 - 06:45 PM

I would also be looking at adding ArraySum, ArrayMult, ArrayExtract.  I have written ArrayJoin that concatinates a single-dimensioned array into a single string.  Yeah, I could add a second delimiter for 2-dimensional arrays.

<{POST_SNAPBACK}>

This would be fantastic Nutster! Built-in array operations would be great! If I can make a suggestion, could you make sure that it is possible to use your ArrayMult to multiply an array by an scalar value (i.e. a single number).

That way we could do something like:

```Dim \$v_1[] = [4, 2, 1]
Dim \$v_2[] = [1, 2, 3]
\$v_3 = ArraySum(\$v_1, ArrayMult(-2, \$v_2))```

and obtain: [2, -2, -5] in \$v_3

Otherwise you'd need to create an array of the same size of \$v_2 to multiply \$v_2 by 2.

Also, are you still going to work on the new declaration syntax?

Cheers,

Angel

### #34 Nutster

Nutster

Developer at Large

• Developers
• 1,450 posts

Posted 05 November 2004 - 07:33 PM

```Dim \$v_1[] = [4, 2, 1]
Dim \$v_2[] = [1, 2, 3]
\$v_3 = ArraySum(\$v_1, ArrayMult(-2, \$v_2))```

and obtain: [2, -2, -5] in \$v_3

Also, are you still going to work on the new declaration syntax?

<{POST_SNAPBACK}>

Here is the plan.

ArrayMult(\$array1) will multiply all elements in an array. Anything that would be interpreted as 0 will cause the function to return 0. ArrayMult(\$array1, 5) would return the array with every element is multiplied by 5; the original array is unchanged. ArrayMult(\$array1, \$array2) would return an array with the corresponding elements of \$array1 and \$array being multiplied. The arrays must be the same size. This is not matrix multiplication. Hmm, ... UDF's I think.

ArraySum(\$array) would return the sum of all elements. ArraySum(\$array1, -8) would subtract 8 from each element of the array. ArraySum(\$array1, \$array2) would return an array with the elements of \$array1 added to the corresponding elements of \$array2. The arrays must be the same size.

I still intend to do the new DIM initialization syntax as well. All of this must wait for RegExp to be fully tested and submitted to Jon. This could take a while as I usually can only spend an hour or two on AutoIt development per day right now.

David Nuttall

Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius
AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

### #35 Angel

Angel

Universalist

• Active Members
• 352 posts

Posted 05 November 2004 - 07:39 PM

Nutster, that is simply perfect!!!

Thanks a lot! Don't worry for the time it will take. There are always workarounds for this, but once it's done it will be really good!

Angel

Here is the plan.

ArrayMult(\$array1) will multiply all elements in an array.  Anything that would be interpreted as 0 will cause the function to return 0.  ArrayMult(\$array1, 5) would return the array with every element is multiplied by 5; the original array is unchanged.  ArrayMult(\$array1, \$array2) would return an array with the corresponding elements of \$array1 and \$array being multiplied.  The arrays must be the same size.  This is not matrix multiplication.  Hmm, ...    UDF's I think.

ArraySum(\$array) would return the sum of all elements.  ArraySum(\$array1, -8) would subtract 8 from each element of the array.  ArraySum(\$array1, \$array2) would return an array with the elements of \$array1 added to the corresponding elements of \$array2.  The arrays must be the same size.

I still intend to do the new DIM initialization syntax as well.  All of this must wait for RegExp to be fully tested and submitted to Jon.  This could take a while as I usually can only spend an hour or two on AutoIt development per day right now.

<{POST_SNAPBACK}>

### #36 Guest_dinave_*

Guest_dinave_*
• Guests

Posted 04 February 2008 - 12:53 PM

I also suppor this request.

### #37 Valik

Valik

Former developer.

• Active Members
• 18,879 posts

Posted 04 February 2008 - 03:29 PM

Why did you resurrect a 3 year old thread to seemingly suggest that you support a feature that's been implemented for 3 years?

### #38 Simucal

Simucal

Universalist

• Active Members
• 777 posts

Posted 05 February 2008 - 02:51 AM

Why did you resurrect a 3 year old thread to seemingly suggest that you support a feature that's been implemented for 3 years?

I actually laughed out loud..
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

### #39 BrettF

BrettF

My Drunk Monkey Guerilla is gonna getcha!

• MVPs
• 7,662 posts

Posted 05 February 2008 - 07:03 AM

Neither can spell It was funny...

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users