Zombie1982 Posted April 6, 2009 Share Posted April 6, 2009 (edited) Good evening, Recently I've been making up something and have so far successfully been able to work around an issue I've been having with my arrays. Now I have hit a snag. I'm using _ArrayToClip to pop stuff from my _ExcelReadArray command into the clipboard, but have never been able to use ,0,0 for some reason. Hopefully this makes some sense. Below is the script I'm using. Func GrabCon(); hopfully grabs WinActivate("Microsoft Excel"); Selects the excel window If WinActive("Microsoft Excel") = 0 Then; Checks (0 means NO) MsgBox(48, "Massive Error", "Failed to open"); Shows the error Exit; Stops the script EndIf; Ends the if statment Global $oExcel ;Global $oExcel = _ExcelBookOpen($Sheet); Opens the spreadsheet _ExcelSheetActivate($oExcel, "Con"); Send("^{HOME}"); sets the excel cell to A1 again $ExcelConGrab = _ExcelReadArray($oExcel, 2, 1, 2, 0); row, colum, number of cells, direction(0=right) ;_ArrayDisplay($ExcelConGrab); Displays array for testing _ArrayToClip($ExcelConGrab,0,0); sends item to the clipboard Basically, the last line is sending nothing to the clip board, yet when I enable the testing there is something defiantly at 0,0. And ideas? Thanks in advance. EDIT: I dont even need an array for what I'm trying to do, _ExcelReadCell will work much better. Edited April 6, 2009 by Zombie1982 Link to comment Share on other sites More sharing options...
erik7426 Posted April 6, 2009 Share Posted April 6, 2009 Good evening, Recently I've been making up something and have so far successfully been able to work around an issue I've been having with my arrays. Now I have hit a snag. I'm using _ArrayToClip to pop stuff from my _ExcelReadArray command into the clipboard, but have never been able to use ,0,0 for some reason. Hopefully this makes some sense. Below is the script I'm using. Func GrabCon(); hopfully grabs WinActivate("Microsoft Excel"); Selects the excel window If WinActive("Microsoft Excel") = 0 Then; Checks (0 means NO) MsgBox(48, "Massive Error", "Failed to open"); Shows the error Exit; Stops the script EndIf; Ends the if statment Global $oExcel ;Global $oExcel = _ExcelBookOpen($Sheet); Opens the spreadsheet _ExcelSheetActivate($oExcel, "Con"); Send("^{HOME}"); sets the excel cell to A1 again $ExcelConGrab = _ExcelReadArray($oExcel, 2, 1, 2, 0); row, colum, number of cells, direction(0=right) ;_ArrayDisplay($ExcelConGrab); Displays array for testing _ArrayToClip($ExcelConGrab,0,0); sends item to the clipboard Basically, the last line is sending nothing to the clip board, yet when I enable the testing there is something defiantly at 0,0. And ideas? Thanks in advance. I've tracked down the problem to Array.au3. _ArrayToClip uses _ArrayToString which contains this code: Func _ArrayToString(Const ByRef $avArray, $sDelim = "|", $iStart = 0, $iEnd = 0) If Not IsArray($avArray) Then Return SetError(1, 0, "") If UBound($avArray, 0) <> 1 Then Return SetError(3, 0, "") Local $sResult, $iUBound = UBound($avArray) - 1 ; Bounds checking If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound If $iStart < 0 Then $iStart = 0 If $iStart > $iEnd Then Return SetError(2, 0, "") ; Combine For $i = $iStart To $iEnd $sResult &= $avArray[$i] & $sDelim Next Return StringTrimRight($sResult, StringLen($sDelim)) EndFunc ;==>_ArrayToString The specific problem is If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound I think they are assuming that if $iEnd = 0 then it must be an error and they are forcing it read to the end of the array. This as far as I can tell is an error in the code otherwise it is impossible to return the 0 index using _ArrayToString or _ArrayToClip. I changed the troublesome line to $iEnd > $iUBound Then $iEnd = $iUBound and the code executes as expected. This should really be corrected in future releases unless I am missing a reason that it was coded this way to begin with... Alternatively that line of code could also be If $iEnd < 0 Or $iEnd > $iUBound Then $iEnd = $iUBound Link to comment Share on other sites More sharing options...
Zombie1982 Posted April 6, 2009 Author Share Posted April 6, 2009 Good gravy, thats some fantastic detective work there, erik7426. Thank you so very much for chasing that up for me. For now, I'll use _ExcelReadCell for what I'm trying to do. 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