litlmike Posted April 25, 2008 Share Posted April 25, 2008 (edited) EDIT: Crud, the forum deleted some of my post when I submitted, trying to fix EDIT: Fixed post I am still trying to figure out how to word this, so please be patient. I have a loop, that grabs some links from a webpage and stores it into an array. I now want to loop through that array (with the stored links), and then grab some data from each of those pages that the links direct me too. However, I want to store that data for use later on, I assume by making a new array (because the data being grabbed is a table). But, is it possible to declare a new array in a loop? So, let us say that the loop will happen 3 times, that means I want 3 new individual arrays, but if I declare a new array, on the second loop, it would just overwrite the previous array. The same thing would occur on loop 3. So the only data I would be left with, it the table grabbed on the 3rd loop. Is there a way to make a loop declare new variable on each time through the loop, so that I end up with a new array variable on each time through the loop? Psuedo-Code as I see it ;Loop through SF Links to get all the relevant data ;Can forsee issue of permanently storing the data For $iCC=1 To Ubound($aSFLinks)-1 ;Navigate to $aSFLinks[$iCC) ;Declare new array ;Grab data from this webpage (data is in a table) ;Store it into the newly declared array Next Code to get links: ;Get ALL SF Links from Services Page ;Put the Username Links into an array for looping later Local $aSFLinks[1] = [""] $oLinks = _IELinkGetCollection ($oIE) For $oLink In $oLinks If StringInStr($oLink.href, "gg_list_generalinfo.cfm?siteID=") Then _ArrayAdd ($aSFLinks, $oLink.href) EndIf Next Edited April 25, 2008 by litlmike _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
sigil Posted April 25, 2008 Share Posted April 25, 2008 You can make a 2D array; think of it as an array of arrays. Each time you execute the loop, use ReDim() to add another array. E.g., dim $myArray[2][1]=["x","y"] $size=ubound($myarray,2) for $c=0 to 9 redim $myArray[2][$size+1] $size=$size+1 next Link to comment Share on other sites More sharing options...
martin Posted April 25, 2008 Share Posted April 25, 2008 EDIT: Crud, the forum deleted some of my post when I submitted, trying to fix EDIT: Fixed post I am still trying to figure out how to word this, so please be patient. I have a loop, that grabs some links from a webpage and stores it into an array. I now want to loop through that array (with the stored links), and then grab some data from each of those pages that the links direct me too. However, I want to store that data for use later on, I assume by making a new array (because the data being grabbed is a table). But, is it possible to declare a new array in a loop? So, let us say that the loop will happen 3 times, that means I want 3 new individual arrays, but if I declare a new array, on the second loop, it would just overwrite the previous array. The same thing would occur on loop 3. So the only data I would be left with, it the table grabbed on the 3rd loop. Is there a way to make a loop declare new variable on each time through the loop, so that I end up with a new array variable on each time through the loop? Psuedo-Code as I see it ;Loop through SF Links to get all the relevant data ;Can forsee issue of permanently storing the data For $iCC=1 To Ubound($aSFLinks)-1 ;Navigate to $aSFLinks[$iCC) ;Declare new array ;Grab data from this webpage (data is in a table) ;Store it into the newly declared array Next Code to get links: ;Get ALL SF Links from Services Page ;Put the Username Links into an array for looping later Local $aSFLinks[1] = [""] $oLinks = _IELinkGetCollection ($oIE) For $oLink In $oLinks If StringInStr($oLink.href, "gg_list_generalinfo.cfm?siteID=") Then _ArrayAdd ($aSFLinks, $oLink.href) EndIf NextYou can have an element of an array which is itself an array. Although it's not so easy to deal with and it can be slow, it might be a suitable approach in your case. So instead of $aSFLinks being 1 -dimensional you could make it 2-dimensional, and store the data array in the second element. Then the array used for the data inside the loop could be the same array all the time and you wouldn't need to keep declaring new ones. Maybe something like this For $iCC=1 To Ubound($aSFLinks)-1 ;Navigate to $aSFLinks[$iCC][0] ;dim will clear the contents of the array Dim $aTemp[10][2];??don't know how this needs to be ;Grab data from this webpage (data is in a table) ;Store data it into $aTemp $aSFLinks[$iCC][1] = $aTemp Next Another way you could do it is to again have $aSFLinks as 2-dimensional, but use the second element as a reference to where the data is. Have an array for the data and as you add data from a web site, redim it if needed to keep it big enough. Every time you start a new web site store the last element used in the data array to the second element of $aSFLinks. Hope that made sense. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
litlmike Posted April 25, 2008 Author Share Posted April 25, 2008 You can have an element of an array which is itself an array. Although it's not so easy to deal with and it can be slow, it might be a suitable approach in your case. So instead of $aSFLinks being 1 -dimensional you could make it 2-dimensional, and store the data array in the second element. Then the array used for the data inside the loop could be the same array all the time and you wouldn't need to keep declaring new ones. Maybe something like this For $iCC=1 To Ubound($aSFLinks)-1 ;Navigate to $aSFLinks[$iCC][0] ;dim will clear the contents of the array Dim $aTemp[10][2];??don't know how this needs to be ;Grab data from this webpage (data is in a table) ;Store data it into $aTemp $aSFLinks[$iCC][1] = $aTemp Next Another way you could do it is to again have $aSFLinks as 2-dimensional, but use the second element as a reference to where the data is. Have an array for the data and as you add data from a web site, redim it if needed to keep it big enough. Every time you start a new web site store the last element used in the data array to the second element of $aSFLinks. Hope that made sense.Interesting, I didn't know you could make an array element another array. This may be a route I can take, I will give it a shot. So then, I assume there is no way to create new variables by looping? Like: For $iCC=0 To 5 Local $sVariable & $iCC Next _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
sigil Posted April 25, 2008 Share Posted April 25, 2008 Interesting, I didn't know you could make an array element another array. This may be a route I can take, I will give it a shot. So then, I assume there is no way to create new variables by looping? Like: For $iCC=0 To 5 Local $sVariable & $iCC Next Actually, you can use Assign(), because it turns a string into a variable name. Like this: for $iCC = 0 to 5 assign("varname"&$iCC,"somevalue") next Link to comment Share on other sites More sharing options...
litlmike Posted April 25, 2008 Author Share Posted April 25, 2008 Actually, you can use Assign(), because it turns a string into a variable name. Like this: for $iCC = 0 to 5 assign("varname"&$iCC,"somevalue") nextOmgosh.... there are so many scripts I have to re-write now.... thanks _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
litlmike Posted April 25, 2008 Author Share Posted April 25, 2008 Actually, you can use Assign(), because it turns a string into a variable name. Like this: for $iCC = 0 to 5 assign("varname"&$iCC,"somevalue") nextI tried your method, but there is an issue. When I try to compile, it says the variable is undeclared, which is true, it has not been declared at the point of compile, but once it runs, it will. However, I cannot declare it before compiling, because I do not know yet how many of these variables there will be. How do I resolve this? ;Loop through SF Links to get all the relevant data ;Can forsee issue of permanently storing the data, how can I name a new array variable, without erasing the last one For $iCC=1 To UBound ($aSFLinks)-1 ;Navigate to link $aSFLinks[$iCC] _IENavigate ($oIE, $aSFLinks[$iCC]) _IELinkClickByText ($oIE, "Historical Performance") ;Get Data from from that page (which is a table of data) ;Get Historical Performance $xCC=0 Do $oTablePerformance = _IETableGetCollection ($oIE, $xCC) $aTableDataPerformance = _IETableWriteToArray ($oTablePerformance, True) ;Store it into a new array Assign ("aTableDataPerformance" & $xCC, $aTableDataPerformance) $xCC+=1 Until ($aTableDataPerformance[0][0] = "Year") _ArrayDisplay($aTableDataPerformance & $iCC) Next _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
evilertoaster Posted April 25, 2008 Share Posted April 25, 2008 Anytime you use assign() to create a variable, you should use eval() to read it. Link to comment Share on other sites More sharing options...
martin Posted April 25, 2008 Share Posted April 25, 2008 Anytime you use assign() to create a variable, you should use eval() to read it.The compiler message is just a warning because it doesn't know about the variable, and it can be ignored (the warning that is).It isn't mandatory to use eval though that would get rid of the warning. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
litlmike Posted April 25, 2008 Author Share Posted April 25, 2008 Good news and bad news. Good news, is that I was able to use Assign and Eval to _ArrayDisplay the tables. Bad news, I can't seem to access the individual elements of the table. It could just be a syntax issue, but I am new to this arena so I was hoping you could save me. The 2 loops work beautifully, except for the line with ConsoleWrite. I think I am telling the compiler: "Console Write the element [0][0] for all instances of variable $aTableDataPerformance". But it no workie. The _arraydisplay works though! ;Loop through SF Links to get all the relevant data For $iCC=1 To UBound ($aSFLinks)-1 ;Navigate to link $aSFLinks[$iCC] _IENavigate ($oIE, $aSFLinks[$iCC]) _IELinkClickByText ($oIE, "Historical Performance") ;Get Table from webpage $oTablePerformance = _IETableGetCollection ($oIE, 5) $aTableDataPerformance = _IETableWriteToArray ($oTablePerformance, True) ;Store it into a new array Assign ("aTableDataPerformance" & $iCC, $aTableDataPerformance) Next For $xCC=1 To $iCC ConsoleWrite (Eval("aTableDataPerformance" & $xCC & "[0]" & "[0]") & @CRLF) $Display = Eval("aTableDataPerformance" & $xCC) _ArrayDisplay($Display, $xCC) Next _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
martin Posted April 25, 2008 Share Posted April 25, 2008 (edited) Good news and bad news. Good news, is that I was able to use Assign and Eval to _ArrayDisplay the tables. Bad news, I can't seem to access the individual elements of the table. It could just be a syntax issue, but I am new to this arena so I was hoping you could save me. The 2 loops work beautifully, except for the line with ConsoleWrite. I think I am telling the compiler: "Console Write the element [0][0] for all instances of variable $aTableDataPerformance". But it no workie. The _arraydisplay works though! ;Loop through SF Links to get all the relevant data For $iCC=1 To UBound ($aSFLinks)-1 ;Navigate to link $aSFLinks[$iCC] _IENavigate ($oIE, $aSFLinks[$iCC]) _IELinkClickByText ($oIE, "Historical Performance") ;Get Table from webpage $oTablePerformance = _IETableGetCollection ($oIE, 5) $aTableDataPerformance = _IETableWriteToArray ($oTablePerformance, True) ;Store it into a new array Assign ("aTableDataPerformance" & $iCC, $aTableDataPerformance) Next For $xCC=1 To $iCC ConsoleWrite (Eval("aTableDataPerformance" & $xCC & "[0]" & "[0]") & @CRLF) $Display = Eval("aTableDataPerformance" & $xCC) _ArrayDisplay($Display, $xCC) Next Bad news and, um , bad news. Assign can't be used with arrays, and I don't think Eval can either. EDIT: You could just use one array, and save the data to an ini file with a section name that was related to th eloop count. Then yoiu can read the data back at any time and there's no complicated array structure to worry about. Otherwise my previous suggestions are an option. Maybe you could get round the Assign/Eval limitation by using DllStructCreate. Assign("aTableDataPerformance" & $xCC,DllstructCreate(....));don't know how yur data needs to be structured. . . . For $n = 1 to UBound($aTemp) - 1 $aTemp[$n] = Dllstructgetdata(Eval("aTableDataPerformance" & $xCC,$n) next Edited April 25, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 25, 2008 Moderators Share Posted April 25, 2008 All the headache and a properly formatted array with redim when necessary could get the job done. 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. 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