litlmike Posted April 24, 2007 Share Posted April 24, 2007 (edited) I get the following error listed below. Because the script loops through several tables while testing a particular element to see if it matches the criteria, if an element does not exist in a table that precedes the table I am 'searching' for, then the script errors out. Is there a way to tell the script to execute the loop, even though an error occured? If not, is there another way to modify this Func below to accomplish the same thing? As a last resort, I can make an entirely different function for this 1-time execution, but it would be nice to optimize the script by keeping it with this one Func. As an example of what is going on: If I am looking for $aTableData[$Dim1][$Dim2] when $Dim1 = 2, yet the current table does not have a 2nd element in the 1st dimension, then I get the range exceeded error, however, eventually if the loop could continue, there will be a table that satifies the criteria, if only I can continue the loop after the error. Hope this makes sense, thanks in advance. Error Message: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Until $aTableData[$Dim1][$Dim2] == $iEnd Until ^ ERROR Code: Func Find_Table_in_Browser ($oIE, $iEnd, $Dim1, $Dim2) ;Get TableData i.e. like a List of Usernames $iCC = 0 Do $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 Until $aTableData[$Dim1][$Dim2] == $iEnd Return $aTableData EndFunc;<==Find_Table_in_Browser() Edit: typos Edited April 24, 2007 by litlmike _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
jvanegmond Posted April 24, 2007 Share Posted April 24, 2007 Error checking!!If Ubound($aTableData,?) = ? Then.... github.com/jvanegmond Link to comment Share on other sites More sharing options...
litlmike Posted April 24, 2007 Author Share Posted April 24, 2007 Error checking!! If Ubound($aTableData,?) = ? Then ....Hmmm... I am not sure what your call to Error Check implies.... I assume you mean I need to implement error checking. Which sounds like a great idea, but I don't know what "Error Checking" really is, or how to set that up in my scripts. I did like your Ubound idea, but I seem to have the same difficulty, in that, I have no way of telling the script to Continue the loop if the error occurs. For example I did the following, but the same road block happens, the Until statement is executed which causes the array to put an end to the script. Any suggestions? Func Find_Table_in_Browser ($oIE, $iEnd, $Dim1, $Dim2) ;Get TableData i.e. like a List of Usernames $iCC = 0 Do $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 If NOT (Ubound($aTableData, 1) < $Dim1 OR Ubound($aTableData, 2) < $Dim2) Then Do $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 Until $aTableData[$Dim1][$Dim2] == $iEnd EndIf Until $aTableData[$Dim1][$Dim2] == $iEnd Return $aTableData EndFunc;<==Find_Table_in_Browser() _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
evilertoaster Posted April 24, 2007 Share Posted April 24, 2007 The runtime error will occure of the line is ran. you can't let it do that, so use ubound() to get the array size first and test it to see if the index is out of range with if-then statment to devert program flow from ever using the array if the index is invalid. Link to comment Share on other sites More sharing options...
jvanegmond Posted April 24, 2007 Share Posted April 24, 2007 Do $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 Until $aTableData[$Dim1][$Dim2] == $iEnd ;to While 1 $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 If UBound($aTableData,1) <= $Dim1 AND UBound($aTableData,2) <= $Dim2 AND _ UBound($aTableData,1) >= 0 AND UBound($aTableData,2) >= 0 AND _ $aTableData[$Dim1][$Dim2] == $iEnd Then ExitLoop EndIf WEndI think this NEVER gets you an Array error. github.com/jvanegmond Link to comment Share on other sites More sharing options...
litlmike Posted April 24, 2007 Author Share Posted April 24, 2007 @evilertoaster I like your feedback and I tried a few approaches that failed, probably because I didn't write the code correctly. Manadar gave me an example I am going to try and run with. Thanks! I think this NEVER gets you an Array error. Thanks for sticking with me on this. I now get this error, how do I troubleshoot this error? It sounds like the same error, phrased in a different manner, is that correct or no? ==> Subscript used with non-Array variable.: If UBound($aTableData,1) <= $Dim1 AND UBound($aTableData,2) <= $Dim2 AND UBound($aTableData,1) >= 0 AND UBound($aTableData,2) >= 0 AND $aTableData[$Dim1][$Dim2] == $iEnd Then If UBound($aTableData,1) <= $Dim1 AND UBound($aTableData,2) <= $Dim2 AND UBound($aTableData,1) >= 0 AND UBound($aTableData,2) >= 0 AND $aTableData^ ERROR _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
evilertoaster Posted April 24, 2007 Share Posted April 24, 2007 hummm.. shouldn't happen but well maybe this works- Do $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 Until $aTableData[$Dim1][$Dim2] == $iEnd ;to While 1 $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 If UBound($aTableData,1) < $Dim1 AND UBound($aTableData,2) < $Dim2 AND UBound($aTableData,1) >= 0 AND UBound($aTableData,2) >= 0 Then if $aTableData[$Dim1][$Dim2] == $iEnd Then ExitLoop EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
litlmike Posted April 25, 2007 Author Share Posted April 25, 2007 @eviltoaster & @manadar thanks again for the help, it allowed me to figure out what was wrong! the Varibale and Ubound were on the wrong sides of the "<=" I have tested it in most settings and it works, but there is one other trouble spot I have to test, that I plan to do in the next hour or so. I will let everyone know. Func Find_Table_in_Browser ($oIE, $iEnd, $Dim1, $Dim2) ;Get TableData i.e. like a List of Usernames $iCC = 0 While 1 $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 If $Dim1 <= UBound($aTableData,1) AND $Dim2 <= UBound($aTableData,2) AND _ UBound($aTableData,1) >= 0 AND UBound($aTableData,2) >= 0 AND _ $aTableData[$Dim1][$Dim2] == $iEnd Then Return $aTableData EndIf WEnd _ArrayPermute()_ArrayUnique()Excel.au3 UDF Link to comment Share on other sites More sharing options...
litlmike Posted April 25, 2007 Author Share Posted April 25, 2007 Final Answer: For those that are interested, here is the final result. I had to add a minus 1 to the Ubound since it is a 0-based index array I am working with and it would cause range exceeded errors otherwise. Thanks for everyone that helped! Func Find_Table_in_Browser ($oIE, $iEnd, $Dim1, $Dim2) ;Get TableData i.e. like a List of Usernames $iCC = 0 While 1 $oTable = _IETableGetCollection ($oIE, $iCC) $aTableData = _IETableWriteToArray ($oTable) $iCC+=1 _ArrayDisplay2D($aTableData) If $Dim1 <= UBound($aTableData,1)-1 AND $Dim2 <= UBound($aTableData,2)-1 AND _ UBound($aTableData,1)-1 >= 0 AND UBound($aTableData,2)-1 >= 0 AND _ $aTableData[$Dim1][$Dim2] == $iEnd Then Return $aTableData EndIf WEnd _ArrayPermute()_ArrayUnique()Excel.au3 UDF 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