Valiante Posted September 18, 2007 Share Posted September 18, 2007 First of all, here's my code; #include <Array.au3> Local $oRS Local $oConn $oConn = ObjCreate("ADODB.Connection") $oRS = ObjCreate("ADODB.Recordset") $oConn.Open("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\temp\mydatabase.mdb") $oRS.Open("Select * FROM Table1", $oConn, 1, 3) $rows = $oRS.RecordCount $array = $oRS.GetRows($rows,0,0) _ArraySort($array) _ArrayDisplay($array) $oConn.Close $oConn = 0 But the following error is returned in the Output; C:\Program Files\AutoIt3\Include\Array.au3 (666) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $t = $array[$i] $t = ^ ERROR >Exit code: 1 The only way I can get it to work is by commenting out the _ArraySort command, but the contents of that column aren't in order and I need them to be. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 18, 2007 Moderators Share Posted September 18, 2007 (edited) How many dimensions is $array? If it's more than 1 (which it looks like) it won't work with _ArraySort(), that's why you are getting the error. Shows how much I know , the help file says it will sort a 2 dimension array, I was always under the assumption it was one.Anyway, how many dimensions is the array? Edited September 18, 2007 by SmOke_N 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...
Valiante Posted September 18, 2007 Author Share Posted September 18, 2007 I'm not sure. The array's created by ADODB.Connection.GetRows and I don't know how that works. When I use _ArrayDisplay it just looks like a basic 1-dimentional array, but what do I know. How can I tell how many dimensions it has? Will I need to use Ubound, or something like that? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 18, 2007 Moderators Share Posted September 18, 2007 I'm not sure. The array's created by ADODB.Connection.GetRows and I don't know how that works. When I use _ArrayDisplay it just looks like a basic 1-dimentional array, but what do I know. How can I tell how many dimensions it has? Will I need to use Ubound, or something like that?Yes that's a good way... MsgBox(64, "Info", "Number of Dimensions: " & _NumDim($array)) Func _NumDim(ByRef $avArray) For $iCC = 64 To 1 Step -1 If UBound($avArray, $iCC) Then Return $iCC Next Return SetError(1, 0, 0) EndFunc 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...
Siao Posted September 18, 2007 Share Posted September 18, 2007 (edited) Why not simply UBound($array, 0)? Edited September 18, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 18, 2007 Moderators Share Posted September 18, 2007 Why not simply UBound($array, 0)?Siao, though I may know a lot of the functions, I have been using them for some time, I'm not sure if "0" always returned the number of dimensions, and I've had no need to look at this function until you pointed it out. If it's been an option the whole time, then I'll say it as I've had no need for the option, and was only looking for a solution I knew would work.That's why I didn't "simply" use the "0" option. 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...
ChrisL Posted September 19, 2007 Share Posted September 19, 2007 Why do you need array sort?Can you not sort the data in the original querry like sql?$oRS.Open("Select * FROM Table1 Order by whaterver the column name to order by is", $oConn, 1, 3)Failing that there some sql stuff in my signature below, maybe you can use the _SQLGetData2D() functionand then do an array sort, infact if you change the connection string in my _sql.au3 file _SQLConnect() function you could probably use all of it [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Valiante Posted September 19, 2007 Author Share Posted September 19, 2007 Chris, While that sounds like a very good idea, I'm afraid I'm just not clever enough to implement it. I read some of the code you guys post and it baffles me - I'm just not a born programmer (I wish I was), but I love AutoIt and the things it lets me achieve. I think I'll try Smoke's idea first, as that seems a little more like something I'd be able to do. I wouldn't dare ask anyone to write code for me, but sometimes I think that's the only way I'd get anything complex to work! Thanks for your input though - it's all very welcome and appreciated. Link to comment Share on other sites More sharing options...
randallc Posted September 19, 2007 Share Posted September 19, 2007 Chris,While that sounds like a very good idea, I'm afraid I'm just not clever enough to implement it. I read some of the code you guys post and it baffles me - I'm just not a born programmer (I wish I was), but I love AutoIt and the things it lets me achieve.I think I'll try Smoke's idea first, as that seems a little more like something I'd be able to do.I wouldn't dare ask anyone to write code for me, but sometimes I think that's the only way I'd get anything complex to work!Thanks for your input though - it's all very welcome and appreciated.Hi,Just for your interst, i found soetimes in vbs with GetRows I had ti go to ".movefirts" first, else I only got 1D array of last row!. Not in au3, at least with ador;egrandall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Valiante Posted September 21, 2007 Author Share Posted September 21, 2007 Yes that's a good way... MsgBox(64, "Info", "Number of Dimensions: " & _NumDim($array)) Func _NumDim(ByRef $avArray) For $iCC = 64 To 1 Step -1 If UBound($avArray, $iCC) Then Return $iCC Next Return SetError(1, 0, 0) EndFunc Hi Smoke, Sorry for not replying sooner, work has been busy of late. Ok, I introduced your code and it returns "Number of Dimensions: 2" in the MsgBox. Link to comment Share on other sites More sharing options...
Valiante Posted September 21, 2007 Author Share Posted September 21, 2007 Success! I borrowed some code from the _ArrayDisplay function in the include file "Array.au3", as I realised part of this function's job is to "convert" a 2D array to a 1D array. Here's the resulting code; #include <Array.au3> Local $oRS Local $oConn Local $1Darray[1] $oConn = ObjCreate("ADODB.Connection") $oRS = ObjCreate("ADODB.Recordset") $oConn.Open("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\temp\mydatabase.mdb") $oRS.Open("Select * FROM RESOURCES", $oConn, 1, 3) $rows = $oRS.RecordCount $2Darray = $oRS.GetRows($rows,0,0) ReDim $1Darray[UBound($2Darray)] For $i = 0 To UBound($2Darray) - 1 For $c = 0 To UBound($2Darray, 2) - 1 $1Darray[$i] &= $2Darray[$i][$c] Next Next _ArrayDisplay($1Darray) _ArraySort($1Darray) _ArrayDisplay($1Darray) $oConn.Close $oConn = 0 The result of which is that the second _ArrayDisplay shows a nicely sorted array, with no error as it's now working on a 1D array. So it would seem then that the statement "This sort functions can handle 1 or 2 dimension arrays" in the Help file for _ArraySort, is somewhat untrue. Thanks for all your help, folks - you inspired me to find the answer! Link to comment Share on other sites More sharing options...
randallc Posted September 21, 2007 Share Posted September 21, 2007 OK! Here's an old example file for 2D sort; ; ArraySortHelp2D.au3 #include <Array.au3> Opt("TrayIconDebug", 1) Dim $aArr[10][5] ; Array for $i=0 to 9 for $j=0 to 4 $aArr[$i][$j]=round(Random($i+$j)) next Next _ArrayDisplay($aArr, "$output b4 sort", 0) ;_ArraySort ( ByRef $a_Array, [$i_Descending[, $i_Base=0[, $i_Ubound=0[, $i_Dim=1[, $i_SortIndex=0]]]]] ) _ArraySort($aArr, 0, 0, -1, UBound($aArr,2), UBound($aArr,2) -1) _ArrayDisplay($aArr, "$output after sort ASC, last column; '_ArraySort($aArr, 0, 0, -1, UBound($aArr,2), UBound($aArr,2) -1)'", 0) _ArraySort($aArr, 1, 0, -1, UBound($aArr,2), 0) _ArrayDisplay($aArr, "$output after sort DESC, first col '_ArraySort($aArr, 1, 0, -1, UBound($aArr,2), 0'", 0) _ArraySort($aArr, 0, 0, -1, UBound($aArr,2), 1) _ArrayDisplay($aArr, "$output after sort ASC col2 (index1) '_ArraySort($aArr, 0, 0, -1, UBound($aArr,2), 1'", 0) _ArraySort($aArr, 1, 0, 5, UBound($aArr,2), 1) _ArrayDisplay($aArr, "$output after sort DESC col2 (index1) (only 5 rows) '_ArraySort($aArr, 0, 0,5, UBound($aArr,2), 1'", 0)Best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW 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