Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/05/2022 in all areas

  1. Many people wanted to see the content of an array inside another array using either _ArrayDisplay or _DebugArrayDisplay. Now it is possible with this UDF. But first I want to give my sincere congratulations to those who have invested long efforts to create ArrayDisplayInternals.au3 (Melba23, jpm, LarsJ, pixelsearch). Most of the code and ingenuity come from those authors. I would say over 90% of the code comes from the original UDF. With this new UDF, you can dig into a tree of arrays inside arrays as deep as you want. There is no limit on the levels of recursion. When you click on an {array} cell, it will bring you a new window (either _ArrayDisplay or _DebugArrayDisplay depending what was called first). Although there is no limit on recursion levels, there is a few limitations that must be mentioned : You need to close all windows before ending the UDF (you can exit script on any level in debug mode) You can only show one array per level at a giving time You cannot manipulate a lower level window untill its child has been closed Example : #include "ArrayDisplayInternalsEX.au3" Local $a = ["a", 2, 3] Local $b = [["x", "y", $a, "z"], [1, $a, 2, 3], [$a, "a", "b", "c"]] Local $c = ["x", "y", 1, $b, "a", 8 ,9 , 10, 11, 12, 13, "abcdef"] _DebugArrayDisplayEX($c, "Test") Enjoy ! ArrayDisplayInternalsEX.au3
    4 points
  2. Dear forum members, I have made a clear step by step tutorial for ControlClick functions together with AU3info. I had struggled a lot with controlclick function and with help in forum I managed it to understand function ControlClick. Because it was so difficult I made this step by step guide. I made it to help others with problems in ControlClick and AU3info. Have fun with it. I would like to thank Jos especially for his great help. Without him I would never managed it to make script with ControClick. ControlClick Tutorial.pdf
    1 point
  3. sudeepjd

    Excel Pivot Tables UDF

    I was looking for a UDF using which I could Add and Update Pivot tables and Pivot Charts in Excel easily and could not find one that I could use. So I build this UDF. It has the following functions : _ExcelPivot_CreateCache ; Easily Create a pivot table data cache from a Sheet _ExcelPivot_CreateTable ; Create a table from a cache at a specified location on the sheet _ExcelPivot_RefreshTable ; Refresh the datatable data with a new cache _ExcelPivot_AddField ; Add a Field and Aggregate function to the Datatable _ExcelPivot_AddFilter ; Adds in the Filter to a specific field _ExcelPivot_ClearFilter ; Removes the filter for a field or all the filters in the table _ExcelPivot_GetRange ; Get specific areas of a Pivot as a Range Object _ExcelPivot_AddChart ; Add a Pivot Chart linked to a specific Pivot table Attached the UDF to this post. Please do let me know if I can improve or add additional functions to it. A detailed example on the usage is below. The excel file and the example can be downloaded from the Example.zip file attached. #include "ExcelPivot.au3" $oExcel = _Excel_Open() $oBook = _Excel_BookOpen($oExcel, @ScriptDir & "\TestPivot.xlsx") ;Create a Sheet to put the pivot into $pSheet = _Excel_SheetAdd($oBook, -1, False, 1) $pSheet.Name = "Pivot" ;Get the cache for the pivot table $pCache = _ExcelPivot_CreateCache($oBook, "Data") ;Add in the Pivot Table from the Cache _ExcelPivot_CreateTable($pCache, $pSheet, "A1", "FruitsPivot") ;Add in the Fields into the Pivot _ExcelPivot_AddField($pSheet, "FruitsPivot", "Category", "Filter") _ExcelPivot_AddField($pSheet, "FruitsPivot", "Product", "Row") _ExcelPivot_AddField($pSheet, "FruitsPivot", "Amount", "Value", "Sum", 1) ;Add in a Running total to the Pivot _ExcelPivot_AddField($pSheet, "FruitsPivot", "Amount", "Value", "Sum", 2, "PercentageRunningTotal", "Product") ;Filter only the fruits _ExcelPivot_Filter($pSheet, "FruitsPivot", "Category", "Fruit") ;Draw a Paretto Chart $chart = _ExcelPivot_AddChart($oBook, $pSheet, "FruitsPivot", "ColumnClustered", "Paretto", "E2", 570) $chart.Chart.FullSeriesCollection(1).ApplyDataLabels $chart.Chart.FullSeriesCollection(2).ChartType = 4 ;Change the percentage to a line graph $chart.Chart.FullSeriesCollection(2).AxisGroup = 2 ;Move it to secondary axis $chart.Chart.Axes(2, 2).MaximumScale = 1 ;Adjust to scale to 100% max ExcelPivot.au3 Example.zip
    1 point
  4. Not a bad idea @pixelsearch. But unfortunately, it is slower because binary search is always searching thru the whole array. With the fact that both input files are sorted, ArraySearch find the value more rapidly (it only needs to read a few records) since there is a very high level of matches. Nevertheless, your 2 cents enlightened me for another way to perform the search even faster. #include <Array.au3> #include <File.au3> Local $hTimer = TimerInit() Local $aDB = FileReadToArray("OrigDbSort.txt") Local $aNew = FileReadToArray("newLinesSort.txt") Local $aAdd[10000] Local $part, $res, $start = 0, $ind = 0 For $i = 0 to UBound($aNew) - 1 $part = GetPart($aNew[$i]) $res = FastSearch($aDB, $part, $start) ;$res = _ArraySearch($aDB, $part, $start, 0, 1, 1) If $res >= 0 Then $aDB[$res] = $aNew[$i] $start = $res + 1 Else $aAdd[$ind] = $aNew[$i] $ind += 1 EndIf Next ConsoleWrite($ind & @CRLF) ;Local $hFile = FileOpen("TempDB.txt", $FO_OVERWRITE) ;_FileWriteFromArray($hFile, $aDB) ;_FileWriteFromArray($hFile, $aAdd, 0, $ind) ;FileClose($hFile) ;RunWait(@ComSpec & " /c sort TempDB.txt /o NewDB.txt", "", @SW_HIDE) ;FileDelete("TempDB.txt") ConsoleWrite(TimerDiff($hTimer) & @CRLF) Func GetPart($string) Return StringMid($string, 1 , Stringinstr($string, "|", 1,6)) EndFunc Func FastSearch(ByRef $array, $str, $begin) Local $txt For $i = $begin to UBound($array) - 1 $txt = GetPart($array[$i]) If $txt == $part Then Return $i If $txt > $part then return -1 Next Return -1 EndFunc Now I am under 1 second !!! To make sure the search was correctly done, I compared the number of new records added with both methods. And they are identical.
    1 point
  5. @Shark007 for GUICtrlSetState to work in your example use Execute GUICtrlSetState(Execute($var), 4) #include <String.au3> Func Check1() ConsoleWrite('> Check1.....' & @CRLF) EndFunc ;==>Check1 Func Check2() ConsoleWrite('> Check2.....' & @CRLF) EndFunc ;==>Check2 Func Check3() ConsoleWrite('> Check3.....' & @CRLF) EndFunc ;==>Check3 Func Check4() ConsoleWrite('> Check4.....' & @CRLF) EndFunc ;==>Check4 ArrStore() Func ArrStore() Local $var Local $arrNames[4] = ["Check1", "Check2", "Check3", "Check4"] For $strName In $arrNames $var = _StringInsert($strName, '$', 0) ;~~ GUICtrlSetState(Execute($var), 4) ;~ <<<<= use Execute Execute($strName & '()') ;~ Method 1 ;Call($strName) ;~ Method 2 Next EndFunc ;==>ArrStore
    1 point
  6. Depending on how your script is structured, you may not even need the Exit keyword. The script will terminate itself when it has done its job. For a detailed answer, however, as @Melba23 already wrote, we need the source code.
    1 point
  7. This could be done easily using regex (text treatment, no array used) Please try this for the concept (raw code - without error checking !!) ; create 80k lines txt file #cs $s = "20211231000000|airCOM|USD|PB air 3 AmSugg||PHRASE|125907|549|0.016|0.59|420.85|||0|0|0|0|49|" $old_line = "20211231000000|gasCOM|USD|gas 1||BROAD|20042|20|0.033|0.59|11.79|||0|0|0|0|0|" Local $txt For $i = 0 to 80000 $txt &= $s & @crlf Next $txt &= $old_line & @crlf FileWrite(@desktopdir & "\test.txt", $txt) #ce ; get from new line the part to be detected - upto the 6° "|" $new_line = "20211231000000|gasCOM|USD|gas 1||BROAD|88888|20|0.033|0.59|11.79|||0|0|0|0|0|" $part = StringRegExpReplace($new_line, '^(.*?\|){6}\K.*', "") Msgbox(0,"", $part) ; get the corresponding line from txt $txt = FileRead(@desktopdir & "\test.txt") $checked_line = StringRegExp($txt, '\Q' & $part & '\E.*', 1)[0] Msgbox(0,"", $checked_line) ; replace it and write new file $txt2 = StringReplace($txt, $checked_line, $new_line) FileWrite(@desktopdir & "\test_new.txt", $txt2)
    1 point
  8. It should work - except if the data is only "displayed" as 10:28:30 PM" which it is Change the format of the cell to "General" or "Number and see what it displays ... does "0.936458333333333" look familiar? it should, because it is what it stands for that specific time. "What you see" in Excel is not always "what you get" About how to convert this in a real time format? No idea, for me, the number looks like a percentage of a full 24 hours; some research should point you to the right conversion formula. Good luck. Edit: Actually I felt good enough to write myself such a function, to convert the time in decimal format to a proper 24 hours or 12 hours format, here it comes: MsgBox(0, "time", _ExcelDecToTime(0.936458333333333)) Func _ExcelDecToTime($dec_value, $format = 0) ;format=0 -> 24 hours, format=1 -> 12 hours $time_sec = $dec_value*86400 $hours = Int($time_sec/3600) If $hours < 10 Then $hours = "0"&$hours $minutes = Int(Mod($time_sec,3600)/60) If $minutes < 10 Then $minutes = "0"&$minutes $seconds = Round(Mod($time_sec,60)) If $seconds < 10 Then $seconds = "0"&$seconds Switch $format Case 0 ;24 hours format Return $hours&":"&$minutes&":"&$seconds Case 1 ;AM/PM format If $hours > 12 Then If Number($hours) = 24 Then Return "12:"&$minutes&":"&$seconds&" AM" Else Return $hours-12&":"&$minutes&":"&$seconds&" PM" EndIf Else If Number($hours) = 0 Then Return "12:"&$minutes&":"&$seconds&" AM" Else Return $hours&":"&$minutes&":"&$seconds&" AM" EndIf EndIf Case Else MsgBox(16, "Flag error", $format&" is not a valid option") EndSwitch EndFunc I'm not sure it is 100% functional, my tests looked OK. If something is wrong - you can easily correct the logic. Edit 2: if you are changing the data format in the same excel file, you might consider having a look at "_ExcelNumberFormat" function from here: http://www.autoitscript.com/forum/index.php?showtopic=34302
    1 point
×
×
  • Create New...