Tiggerstrigger

How to create arrays in a for loop

5 posts in this topic

I want to create an multiple arrays using a for loop but i am unsure how to do that. 
I would like to do something like this. 
 

For $i = 0 To 10 Step 1

local $array & $i [$i]

Next 

but i am not sure how to work around the sytax

thanks for the help.

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Can you please tell us why you need to dynamically create arrays?
I never had the need to create arrays this way and I'm sure it can become quite complex.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

may be you are looking for this 
 

#include <Array.au3>

Local $aArray[1]
_ArrayAdd($aArray, "one thing")
_ArrayAdd($aArray, "another thing")
_ArrayAdd($aArray, "another thing")
For $i = 1 To 20
_ArrayAdd($aArray, $i)
Next

For $i = 0 To UBound($aArray)-1
    ConsoleWrite($aArray[$i] & @CRLF)
Next

https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayAdd.htm

Share this post


Link to post
Share on other sites

Thanks. 

 

sure, i am reading multiple text files with hardware information one at a time and  saving manipulated data (simple strings) to an array. 

I want to create an overview about the number of machines that are using a specific hardware element and the number of machines that are using a similar/ the same hardware configuration while saving which machine has what by saving the ip addresses corresponding to the machines and their hardware configuration.
the data in the Textfile can look like this (file Attached)

 

I am not very experienced at all this is my second thing that i am doing ^^ 

I am very happy to find out easier,better or just alternativ ways to archiving my goal.

 

My thinking was cycling through the files with a loop and reading the hardware information in an array, $aCurrentHardwareConfig[Category like Motherboard] [Specific Part saved as the string behind :] ( this Array will then compare itself with $aOverviewHardwareConfig wich saves the added up strings from Specific Parts, a counter and the added up Ip Adresses of the machines that got true when comparing the added up string of hardware. If it gets false it wil create a new array entry with his added up hardware from $aCurrentHardwareConfig and add the ip address saved in the .txt . 


I also wanted to Save the number of machines with a spefic hardware part. Thats why i wanted to create one Array for each category so i can just save the Diffrent hardware parts in an array with a counter and add one if a new graphics card gets discovered.

That would mean i need to creat an Array for every category but the categories arent fixed. 

That was probably to much information. Its hard to gague whats important for another person... 
Thanks for the interest.

 

 


 

 

Hardwareinfo.txt

Share this post


Link to post
Share on other sites
Quote

That would mean i need to creat an Array for every category but the categories arent fixed. 

I would create a single array for this with the first column holding the category. I think this makes the handling much easier compared to handle a growing number of arrays.

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

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