langthang084 Posted November 25, 2015 Share Posted November 25, 2015 When I use _arraySort after read "Data.xls", the result is sort on a first character of the number (like 93, 92, 91, 90, 9, 89, 88...) but when use _arraysort with only the number, it's normalCould anyone help me?#include <array.au3> #include <file.au3> #include <excel.au3> opt("WinTitleMatchMode", 2) $PathListDonThuoc = @ScriptDir & "\Data.xls" $SoBA_Start = 25000 Local $oApp2 = _Excel_Open() Local $SourceListDonThuoc = _Excel_BookOpen($oApp2, $PathListDonThuoc) $ListDonThuoc = _Excel_SheetList ( $SourceListDonThuoc ) _ArrayDisplay($ListDonThuoc, "DS ĐƠN THUOC") Local $SoSheetCanXoa[1][2] for $b = 0 to UBound($ListDonThuoc) - 1 ToolTip($b) $Name_BA = $ListDonThuoc[$b][0] $SoBA2 = StringSplit($Name_BA, " ") $numEnd = UBound($SoBA2) - 1 $Name = $SoBA2[$NumEnd - 1] $SoBA_Sheet = $SoBA2[$NumEnd] ; if Number($SOBA_Sheet) < Number($SoBA_Start) Then _ArrayAdd($SoSheetCanXoa, $b + 1 & "|" & $ListDonThuoc[$b][0]) ContinueLoop EndIf Next _ArrayDelete($SoSheetCanXoa, 0) _ArrayDisplay($SoSheetCanXoa, "So sheet can xoa - BEFORE") _ArraySort($SoSheetCanXoa, 1,0,0,0) _ArrayDisplay($SoSheetCanXoa, "So sheet can xoa") Data.xls Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 25, 2015 Moderators Share Posted November 25, 2015 langthang084,If you want the elements sorted as numbers, you need to force them into the correct datatype using Number before sorting - otherwise you will, as you have already discovered, get them sorted according to the ASCII values of the characters. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
langthang084 Posted November 26, 2015 Author Share Posted November 26, 2015 (edited) langthang084,If you want the elements sorted as numbers, you need to force them into the correct datatype using Number before sorting - otherwise you will, as you have already discovered, get them sorted according to the ASCII values of the characters.I change _ArrayAdd($SoSheetCanXoa, $b + 1 & "|" & $ListDonThuoc[$b][0])to _ArrayAdd($SoSheetCanXoa, Number($b + 1) & "|" & $ListDonThuoc[$b][0])But it dont work. But if I use (with Local $SoSheetCanXoa[1])_ArrayAdd($SoSheetCanXoa, $b + 1)then it works normally Edited November 26, 2015 by langthang084 Link to comment Share on other sites More sharing options...
water Posted November 26, 2015 Share Posted November 26, 2015 Because with& "|" & $ListDonThuoc[$b][0])you do a string concatenation and the result is a string again. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
langthang084 Posted November 26, 2015 Author Share Posted November 26, 2015 Thanks Water. I've sorted normally. But why when use _excel_SheetDelete (Sheet Number's sort descending), the result is failexpandcollapse popup#include <array.au3> #include <file.au3> #include <excel.au3> opt("WinTitleMatchMode", 2) $PathListDonThuoc = @ScriptDir & "\Data.xls" $SoBA_Start = 25000 Local $oApp2 = _Excel_Open() Local $SourceListDonThuoc = _Excel_BookOpen($oApp2, $PathListDonThuoc) $ListDonThuoc = _Excel_SheetList ( $SourceListDonThuoc ) _ArrayDisplay($ListDonThuoc, "DS ĐƠN THUOC") Local $SoSheetCanXoa[1][2] for $b = 0 to UBound($ListDonThuoc) - 1 ToolTip($b) $Name_BA = $ListDonThuoc[$b][0] $SoBA2 = StringSplit($Name_BA, " ") $numEnd = UBound($SoBA2) - 1 $Name = $SoBA2[$NumEnd - 1] $SoBA_Sheet = $SoBA2[$NumEnd] ; if Number($SOBA_Sheet) < Number($SoBA_Start) Then _arrayadd($SoSheetCanXoa, "") $SoSheetCanXoa[UBound($SoSheetCanXoa) - 1][0] = $b + 1 $SoSheetCanXoa[UBound($SoSheetCanXoa) - 1][1] = $ListDonThuoc[$b][0] ContinueLoop EndIf Next _ArrayDelete($SoSheetCanXoa, 0) _ArraySort($SoSheetCanXoa, 1,0,0,0) _ArrayDisplay($SoSheetCanXoa, "So sheet can xoa") for $c = UBound($SoSheetCanXoa) - 1 to 0 step -1 $DelSheet = $SoSheetCanXoa[$c][0] _Excel_SheetDelete($SourceListDonThuoc, $DelSheet) Next $ListDonThuoc = _Excel_SheetList ( $SourceListDonThuoc ) _ArrayDisplay($ListDonThuoc, "DS ĐƠN THUOC") Link to comment Share on other sites More sharing options...
water Posted November 26, 2015 Share Posted November 26, 2015 When deleting which sheet do you get which error (means what is the value of macro @error)? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
langthang084 Posted November 26, 2015 Author Share Posted November 26, 2015 (edited) @Water: @error = 2 Edited November 26, 2015 by langthang084 Link to comment Share on other sites More sharing options...
langthang084 Posted November 26, 2015 Author Share Posted November 26, 2015 And there're some sheet dont have error when delete, but they arent been deleted Link to comment Share on other sites More sharing options...
water Posted November 26, 2015 Share Posted November 26, 2015 According to the help file (hint!) this means: "Specified sheet does not exist. @extended is set to the COM error code".Could you write the names of the sheets you want to delete to the console and then check that they exist? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
langthang084 Posted November 26, 2015 Author Share Posted November 26, 2015 (edited) I change to delete by the name of the sheet, then it works. But I dont know why when delete by the number of the sheet (like above), it's wrong. (My script find the number of the sheet in my excel file (data.xls), so the sheet must exist) Edited November 26, 2015 by langthang084 Link to comment Share on other sites More sharing options...
water Posted November 26, 2015 Share Posted November 26, 2015 Don't know. I can only guess that the number is wrong and a sheet with this number no longer exists. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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