# [Solved] Multi Dim Array Problem

## Recommended Posts

Hi,

how can I avoid that the previous values are not set to zero?

Here an example:

```#include <Array.au3>
\$f = 10
Dim \$aTest [\$f][1]

\$y1 = 3
\$y2 = 5
\$y3 = 7
For \$i = 0 To 3 ;writes numbers from 0 to 3 to array[3] (zero based)
ReDim \$aTest[\$f][\$i+1]
\$aTest[\$y1][\$i] = \$i
Next
For \$i = 0 To 5
ReDim \$aTest[\$f][\$i+1] ; this will set array[3][1] to 0
\$aTest[\$y2][\$i] = \$i
Next
For \$i = 0 To 7
ReDim \$aTest[\$f][\$i+1] ; this will set array[3][1] and array[5][1]  to 0
\$aTest[\$y3][\$i] = \$i
Next

_ArrayDisplay(\$aTest)```

How it is possible to save also the values in array[3] and array[5]?

Thanx.

UEZ

Edited by UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

Hi,

how can I avoid that the previous values are not set to zero?

Here an example:

```#include <Array.au3>
\$f = 10
Dim \$aTest [\$f][1]

\$y1 = 3
\$y2 = 5
\$y3 = 7
For \$i = 0 To 3 ;writes numbers from 0 to 3 to array[3] (zero based)
ReDim \$aTest[\$f][\$i+1]
\$aTest[\$y1][\$i] = \$i
Next
For \$i = 0 To 5
ReDim \$aTest[\$f][\$i+1] ; this will set array[3][1] to 0
\$aTest[\$y2][\$i] = \$i
Next
For \$i = 0 To 7
ReDim \$aTest[\$f][\$i+1] ; this will set array[3][1] and array[5][1]  to 0
\$aTest[\$y3][\$i] = \$i
Next

_ArrayDisplay(\$aTest)```

How it is possible to save also the values in array[3] and array[5]?

Thanx.

UEZ

That code and the question make no sense at all. Start over and just describe what you want the final array to be like.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

That code and the question make no sense at all. Start over and just describe what you want the final array to be like.

My aim is to have a multi dim array with following content:

[0]

[1]

[2]

[3]["0"]["1"]["2"]["3"]

[4]

[5]["0"]["1"]["2"]["3"]["4"]["5"]

[6]

[7]["0"]["1"]["2"]["3"]["4"]["5"]["6"]["7"]

[8]

[9]

It should be dynamically increasable. E.g. the content of n files should be added to

array[file_1][line1][line2][line3][etc.]

array[file_2][line1][line2][line3][etc.]

...

array[file_n][line1][line2][line3][etc.]

The amount of files and its content is variable.

Thanx.

UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

My aim is to have a multi dim array with following content:

[0]

[1]

[2]

[3]["0"]["1"]["2"]["3"]

[4]

[5]["0"]["1"]["2"]["3"]["4"]["5"]

[6]

[7]["0"]["1"]["2"]["3"]["4"]["5"]["6"]["7"]

[8]

[9]

It should be dynamically increasable. E.g. the content of n files should be added to

array[file_1][line1][line2][line3][etc.]

array[file_2][line1][line2][line3][etc.]

...

array[file_n][line1][line2][line3][etc.]

The amount of files and its content is variable.

Thanx.

UEZ

The entire array is declared with a fixed number of elements in each dimension. You can't have 4 at one point, 6 in another, and 8 in yet another. You would have to declare (or redim) the entire array as [n][8] and just ignore unused elements.

Redim takes time, and I suspect you code would be very slow if you keep doing it over and over again. Better to determine as early as possible what size you need for the array and redim only once before putting the data in. In addition, if you redim to a smaller number in any dimension, the data will be truncated at that many elements in the entire array. So your redim should be conditional on the array not already being big enough for the data you want to put in.

Does that cover what you were trying to do?

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

The entire array is declared with a fixed number of elements in each dimension. You can't have 4 at one point, 6 in another, and 8 in yet another. You would have to declare (or redim) the entire array as [n][8] and just ignore unused elements.

Redim takes time, and I suspect you code would be very slow if you keep doing it over and over again. Better to determine as early as possible what size you need for the array and redim only once before putting the data in. In addition, if you redim to a smaller number in any dimension, the data will be truncated at that many elements in the entire array. So your redim should be conditional on the array not already being big enough for the data you want to put in.

Does that cover what you were trying to do?

Ok, thanks for your answer. I thought it was possible to redim multi dim arrays in that way.

I wrote a GUI which reads the filenames from a folder to a list. These files are encrypted and have a check sum in each line to avoid manipulation. If I double click on one of the filenames it will decrypt the content by reading the file line by line and displays the content in another list.

To avoid decrpyting everytime when clicking on the same filename I wanted to cache the decrypted content in a multi dim array.

The problem is that the amount of files and it contents (lines) is not static.

Do you have another idea how to cache the content of the files without writing it back to a file because memory operations are much faster!

Anyway, thanks for your fast response

UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

Why not just skip the empty elements as suggested? If \$myArray[1][0] = "" Then ...

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.

##### Share on other sites

Do you have another idea how to cache the content of the files without writing it back to a file because memory operations are much faster!

The complication comes from trying to put more than one file in a single array. I would put each file in its own array with FileReadToArray(). You get a nice, simple, 1D array for each file that way.

Or perhaps append the additional lines of each file to the end of a single 1D array, with some kind of delimiter between them.

AutoIt can also store an entire array as an element in another array, but there are performance issues with doing that.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

To give you a better picture of the situation, here is a screenshot of the GUI (the GUI is a part of a CMD tool which collects several information from systems):

On the left side you can see the files located in the path above. It may differ - it can be more or less. On the right side you can see the decrypted content. Here , e.g the services of all systems belongs to Services_KSB.sv. The size and thus the lines depends on the amount of systems.

In this case it has 27878 lines from 241 servers which took approx. 205 sec. to load line by line and decode it.

Why it is encrypted (and each line has a checksum)? Because the information should be imported to a db and it should not be manipulated before the import.

I've to think about the two possible alternatives: using one 1D array append the content to it or to create n 1D arrays with the content of each file.

nD array is much complicated in that case.

UEZ

Edited by UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

I would just use an array of Scripting.Dictionary objects:

#374426

##### Share on other sites

I would just use an array of Scripting.Dictionary objects:

#374426

Thanks for the hint . I will play around with array of Scripting.Dictionary to see whether I can implement it

UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

Why not just skip the empty elements as suggested? If \$myArray[1][0] = "" Then ...

Done.

I scanned all files for max. lines and created the array with \$aCache[amount of files][max. lines] without ReDim each time the array.

Working nice -> increased speed around factor 3

THANX.

UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

## Create an account

Register a new account

×

• Wiki

• Back

• Git