gottygolly Posted August 22, 2015 Share Posted August 22, 2015 I'm working on a script and I'm trying to define a 2d array inside a for loop.Is it possible to do it?Eg: For $i = 0 to 50 local $array[50][2] = [[$i,$var[$i]] NextIf this is possible how would I get the information from the array?Something like: $array[5][1]?I'm really confused on this and any help will be awesome.(If you can not do this how would I go about doing it a different way?)Thanks in advance! Link to comment Share on other sites More sharing options...
iamtheky Posted August 23, 2015 Share Posted August 23, 2015 #include<array.au3> local $array[50][2] For $i = 0 to ubound($array) - 1 $array[$i][0] = $i $array[$i][1] = "var" & $i Next _ArrayDisplay($array) gottygolly 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Malkey Posted August 23, 2015 Share Posted August 23, 2015 It is best to define or declare the array outside of any loop. Then, assign values to the elements of the array inside of a loop.#include <Array.au3> Local $array[50][2] Local $var[50] = [49, 48, 47, 46, 45, 44, 43, 42, 41, 40] For $i = 0 To 49 $array[$i][0] = $i $array[$i][1] = $var[$i] Next MsgBox(0, "Result", "$array[5][0] = " & $array[5][0] & @CRLF & @CRLF & "$array[5][1] = " & $array[5][1]) _ArrayDisplay($array)See tutorial on arrays https://www.autoitscript.com/wiki/Arrays gottygolly 1 Link to comment Share on other sites More sharing options...
gottygolly Posted August 23, 2015 Author Share Posted August 23, 2015 Thanks for the replies, I put it in a loop because the [50] can change since I am grabbing the information from a website that updates regularly.Malkey, your example works but boththose is the one i used since it is more condensed and works aswell.Thanks for all your help guys! Link to comment Share on other sites More sharing options...
iamtheky Posted August 23, 2015 Share Posted August 23, 2015 (edited) Under no circumstances should you use my solution over Malkey's, at all, ever. In this case my script is only more condensed because I am lazy and was not about to make $var for you, he was kind enough to do so. They are, for all intents, the same (this time, but thats just luck). Edited August 23, 2015 by boththose Surya and kylomas 2 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Gianni Posted August 23, 2015 Share Posted August 23, 2015 <zap> .... since I am grabbing the information from a website that updates regularly. ....<\zap>p.s.... don't know if this can be useful for your case, anyway, just for the record, if data that you want to grab from the web site are in an html Table, then you could also consider the _IETableWriteToArray() function, that simply grabs all the data from the table for you and returns them in an ready made array. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now