Leaderboard
Popular Content
Showing content with the highest reputation on 03/31/2021 in all areas
-
Improving _ArrayDisplay speed
CYCho and one other reacted to pixelsearch for a topic
Hi everybody when using _ArrayDisplay, I found a way to drastically reduce a listview load time (and later its sorting time when clicking on a column header) . We discussed of this a year ago with @jpm in this thread and I applied it to _ArrayDisplay just now. 1) The 1st script below uses the original functions of AutoIt It works on a 2D array of 10.000 rows & 10 columns (you may change that if you want) When you run this 1st script, the Console will indicate the number of seconds it takes to populate the listview. Please note this number somewhere so you'll compare it later with the 2nd script's number. #include <Array.au3> ; original #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Opt("MustDeclareVars", 1) Global $hTimer Example() ;================================================== Func Example() _SplashOn("1 - Filling Array") Local $iRowMax = 10000, $iColMax = 10, $aArray[$iRowMax][$iColMax] For $i = 0 To $iRowMax - 1 For $j = 0 To $iColMax - 1 $aArray[$i][$j] = "Row " & $i & " / Col " & $j Next Next _ArrayShuffle($aArray) SplashOff() MsgBox($MB_TOPMOST, "Shuffled Array is ready", "Click to launch _ArrayDisplay original") _SplashOn("2 - Populating Listview") AdLibRegister(TimeToLoad) $hTimer = TimerInit() _ArrayDisplay($aArray, "Speed test ArrayDisplay Original") EndFunc ;==>Example ;================================================== Func TimeToLoad() ; Adlib If WinActive("Speed test ArrayDisplay Original") Then ConsoleWrite(TimerDiff($hTimer) / 1000 & @lf) AdLibUnRegister(TimeToLoad) SplashOff() EndIf EndFunc ;==>Slider ;================================================== Func _SplashOn($sFirstLine, $sSecondLine = "please wait...") SplashTextOn("", $sFirstLine & @CRLF & $sSecondLine, _ 250, 50, -1, -1, $DLG_NOTITLE + $DLG_TEXTVCENTER) EndFunc ;==>_SplashOn 2) The 2nd script below uses 2 "speed" files : ArrayDisplayInternals2.au3 and ArrayDisplayInternals_Fill.au3 You should notice that the listview appears much quicker and the Console should reflect it, maybe 2, 3 or 4 times faster. ; Array.au3 is not used during this speed test #include "ArrayDisplayInternals2.au3" ; increased speed (listview fill & sort) #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Opt("MustDeclareVars", 1) Global $hTimer Example() ;================================================== Func Example() _SplashOn("1 - Filling Array") Local $iRowMax = 10000, $iColMax = 10, $aArray[$iRowMax][$iColMax] For $i = 0 To $iRowMax - 1 For $j = 0 To $iColMax - 1 $aArray[$i][$j] = "Row " & $i & " / Col " & $j Next Next _ArrayShuffle($aArray) SplashOff() MsgBox($MB_TOPMOST, "Shuffled Array is ready", "Click to launch _ArrayDisplay2") _SplashOn("2 - Populating Listview") AdLibRegister(TimeToLoad) $hTimer = TimerInit() _ArrayDisplay2($aArray, "Speed test ArrayDisplay2 Patched") EndFunc ;==>Example ;================================================== Func TimeToLoad() ; Adlib If WinActive("Speed test ArrayDisplay2 Patched") Then ConsoleWrite(TimerDiff($hTimer) / 1000 & @lf) AdLibUnRegister(TimeToLoad) SplashOff() EndIf EndFunc ;==>Slider ;================================================== Func _SplashOn($sFirstLine, $sSecondLine = "please wait...") SplashTextOn("", $sFirstLine & @CRLF & $sSecondLine, _ 250, 50, -1, -1, $DLG_NOTITLE + $DLG_TEXTVCENTER) EndFunc ;==>_SplashOn ; #FUNCTION# ==================================================================================================================== ; Author ........: randallc, Ultima ; Modified.......: Gary Frost (gafrost), Ultima, Zedna, jpm, Melba23, AZJIO, UEZ - _ArrayDisplay() renamed _ArrayDisplay2() in this speed test ; =============================================================================================================================== Func _ArrayDisplay2(Const ByRef $aArray, $sTitle = Default, $sArrayRange = Default, $iFlags = Default, $vUser_Separator = Default, $sHeader = Default, $iMax_ColWidth = Default) #forceref $vUser_Separator Local $iRet = __ArrayDisplay_Share($aArray, $sTitle, $sArrayRange, $iFlags, Default, $sHeader, $iMax_ColWidth, 0, False) Return SetError(@error, @extended, $iRet) EndFunc ;==>_ArrayDisplay2 ; #FUNCTION# ==================================================================================================================== ; Author ........: Melba23 ; Modified.......: copied here because Array.au3 is not used during this speed test ; =============================================================================================================================== Func _ArrayShuffle(ByRef $aArray, $iStart_Row = 0, $iEnd_Row = 0, $iCol = -1) ; Fisher–Yates algorithm If $iStart_Row = Default Then $iStart_Row = 0 If $iEnd_Row = Default Then $iEnd_Row = 0 If $iCol = Default Then $iCol = -1 If Not IsArray($aArray) Then Return SetError(1, 0, -1) Local $iDim_1 = UBound($aArray, $UBOUND_ROWS) If $iEnd_Row = 0 Then $iEnd_Row = $iDim_1 - 1 If $iStart_Row < 0 Or $iStart_Row > $iDim_1 - 1 Then Return SetError(3, 0, -1) If $iEnd_Row < 1 Or $iEnd_Row > $iDim_1 - 1 Then Return SetError(3, 0, -1) If $iStart_Row > $iEnd_Row Then Return SetError(4, 0, -1) Local $vTmp, $iRand Switch UBound($aArray, $UBOUND_DIMENSIONS) Case 1 For $i = $iEnd_Row To $iStart_Row + 1 Step -1 $iRand = Random($iStart_Row, $i, 1) $vTmp = $aArray[$i] $aArray[$i] = $aArray[$iRand] $aArray[$iRand] = $vTmp Next Return 1 Case 2 Local $iDim_2 = UBound($aArray, $UBOUND_COLUMNS) If $iCol < -1 Or $iCol > $iDim_2 - 1 Then Return SetError(5, 0, -1) Local $iCol_Start, $iCol_End If $iCol = -1 Then $iCol_Start = 0 $iCol_End = $iDim_2 - 1 Else $iCol_Start = $iCol $iCol_End = $iCol EndIf For $i = $iEnd_Row To $iStart_Row + 1 Step -1 $iRand = Random($iStart_Row, $i, 1) For $j = $iCol_Start To $iCol_End $vTmp = $aArray[$i][$j] $aArray[$i][$j] = $aArray[$iRand][$j] $aArray[$iRand][$j] = $vTmp Next Next Return 1 Case Else Return SetError(2, 0, -1) EndSwitch EndFunc ;==>_ArrayShuffle You may also notice that sorting on a column is much faster with the 2nd script, compared to the 1st script. Thanks for readers who intend to test this. Just place all 4 files in a folder (i.e. the 2 preceding scripts + ArrayDisplayInternals2.au3 + ArrayDisplayInternals_Fill.au3) . There is nothing to change in AutoIt folders. Please report if something went wrong or should be improved as I just ended this today. I already know that Global variable names which were added are perfectible, because they should follow the way ArrayDisplay "names" its variables, so they won't interfere with user's variables names. For the curious ones, the differences between the original file ArrayDisplayInternals.au3 and the "speed" file ArrayDisplayInternals2.au3 are found in 5 sections, delimited like this : ;********** Speed patch 1 start ********* ... ;********** Speed patch 1 end ********* Here are the 2 files to download : ArrayDisplayInternals2.au3 ArrayDisplayInternals_Fill.au32 points -
How to get an apostrophe - (Locked)
Musashi and one other reacted to JockoDundee for a topic
Sorry, but as a matter of principle, I refuse to work with aHoles[]2 points -
You could use one of the multiple IPCs available. I made an example using my WCD-IPC. As you can see it is very easy to create : Script 1 (Server) : #include <Constants.au3> #include <GUIConstants.au3> #include "WCD_IPC.au3" $FileName = @ScriptDir & '\Test.xlsx' If Not FileExists($FileName) Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "File not found") ;Basic GUI $oExcelDoc = ObjGet($FileName) ; Get an excel Object from an existing filename If Not IsObj($oExcelDoc) Then Exit MsgBox($MB_SYSTEMMODAL, "", "The Excel workbook to display in main GUI could not be found.") Local $hGUI = GUICreate("", 826, 303, -1, -1, $WS_MINIMIZEBOX + $WS_SYSMENU + $WS_CLIPCHILDREN) GUICtrlCreateObj($oExcelDoc, 0, 0, 826, 300) ;Turns off all command bars in excel to prevent user from making changes For $Bar In $oExcelDoc.CommandBars If $Bar.Enabled = True Then $Bar.Enabled = False If $Bar.Visible = True Then $Bar.Visible = False Next $oExcelDoc.Application.Activesheet.Range("A2").Select $oExcelDoc.Application.ActiveWindow.FreezePanes = True $oExcelDoc.Application.ActiveWindow.DisplayHeadings = False $oExcelDoc.Application.DisplayFormulaBar = False $oExcelDoc.Application.CommandBars("Worksheet Menu Bar").Controls("Insert").Enabled = False $oExcelDoc.Application.CommandBars("Worksheet Menu Bar").Controls("Insert").Visible = False $oExcelDoc.Application.CommandBars("Shadow Settings").Visible = False $oExcelDoc.Application.DisplayScrollBars = True $oExcelDoc.Application.DisplayStatusBar = False GUISetState() $oSheet = $oExcelDoc.Application.Activesheet Local $hServer = _WCD_CreateServer () If @error Then Exit MsgBox ($MB_SYSTEMMODAL, "Error", "Unable to create WCD server") Local $aReq, $iData, $aPack While True If _WCD_Server_IsRequestAvail() Then $aReq = _WCD_Server_GetRequest() $iData = @extended $aPack = StringSplit($aReq[1], "|", $STR_NOCOUNT) Switch $iData Case 1 ; set numeric $oSheet.Range($aPack[0]).value = Number($aPack[1]) Case 2 ; set string $oSheet.Range($aPack[0]).value = String($aPack[1]) EndSwitch EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $oExcelDoc.Close ExitLoop EndSwitch WEnd Script 2 (Client) : #include <Constants.au3> #include <GUIConstants.au3> #include "WCD_IPC.au3" Opt ("MustDeclareVars", 1) Global $hWnd = _WCD_CreateClient ("Test WCD Client") Global $hWndServer = _WCD_GetServerHandle () ConsoleWrite ("Server = " & $hWndServer & " Client = " & $hWnd & @CRLF) _WCD_Send($hWnd, $hWndServer, 1, "C5|123.4") ; set numeric data Sleep (500) _WCD_Send($hWnd, $hWndServer, 2, "C6|Once upon") ; set string Sleep (500) See my signature for Fast and Simple WCD-IPC.2 points
-
Understand you don't mean to disrespect ...but this is not the smartest question in these forums and would advice you to go there.1 point
-
endtro, Welcome to the AutoIt forums. This is no doubt a matter of a different display scaling on the affected computer. There are plenty of threads about this on the forum if you search. M231 point
-
val >> 2
crackdonalds reacted to pseakins for a topic
It really is terribly hard to find in the help, but the answer is BitShift, or BitRotate https://www.autoitscript.com/autoit3/docs/functions/BitShift.htm https://www.autoitscript.com/autoit3/docs/functions/BitRotate.htm1 point -
Passing argument to a running AutoIT EXE - (Moved)
OhBobSaget reacted to JockoDundee for a topic
In that case try this as well: Local $sPDFDir=@TempDir & "\PDFMerge\", $sArgs, $sFname, $hSearch DirCreate($sPDFDir) FileWrite($sPDFDir & @AutoItPID, $CmdLine[1]) If FileMove($sPDFDir & @AutoItPID, $sPDFDir & "master") Then Sleep(500) $hSearch=FileFindFirstFile($sPDFDir & "*.*") Do $sArgs&=FileRead($sPDFDir & FileFindNextFile($hSearch)) & " " Until @Error Run("YourProgram.exe " & $sArgs) EndIf Sleep(1000) DirRemove($sPdfDir, 1) It’s just the one program, no UDFs, based on the method I described in my first post. I would have provided code then, but as I said, there doesn’t seem to be an especially elegant method. However, now that argumentum has thrown down the gauntlet, with his “simplest of all solutions”, I can’t resist And with all due respect to both @argumentum and @Nine, both whom I do respect, unless your using the their UDFs already, there is little reason to incorporate those libraries just for a convenience script. No doubt they will work, but if you want to change something in a year, you may not want to be reacquainting yourself with SQL or mailslots just to do it. For instance, if you are having problems with my code, you can just comment out the last DirRemove statement, and then look in the sPDFDir directory to see what is happening, it’s all just text files in a directory that disappears after use. I’ve tested with 10 or so files, just compile the code (without the /console option) to an .exe, and let me know if it runs in your environment ok.1 point -
[SOLVED] _ArrayDelete example not working?
FrancescoDiMuro reacted to JackER4565 for a topic
Do'h thanks so much!!1 point -
[SOLVED] _ArrayDelete example not working?
JackER4565 reacted to FrancescoDiMuro for a topic
When using the $vRange as a 1D array, you have to specify the number of elements to delete in the 0th element of your $vRange array, as stated in the Help file: $vRange can also be a 1D array listing all rows to be deleted with the count in the [0] element. Cheers1 point -
Help with some code (printing Variable o Msgbox)
JackER4565 reacted to FrancescoDiMuro for a topic
@Animare Remove double quotes around the variable name, since in this way it is interpreted literally, and not as a variable. If you need/want to use the variable in such way, then you need to add to your script the option Opt("ExpandVarStrings", 1)1 point -
[Solved] Strange behaviour when running from command line
argumentum reacted to TheXman for a topic
Here's a working example of an HTTP POST with error checking. If you force errors, like giving it a badly formatted URL or making a COM error like using .SetHeaders instead of .SetRequestHeader, you will see how the error checking and COM error handler works. #include <Constants.au3> http_post_example() Func http_post_example() Const $POST_DATA = '{"fld1": "This is a test string", "fld2": true}' Local $oHttp = Null, $oComErr = Null ;Register COM Error Handler $oComErr = ObjEvent("AutoIt.Error", com_error_handler) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to register COM error handler - @error = " & @error) ;Create HTTP COM object $oHttp = ObjCreate("winhttp.winhttprequest.5.1") If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to create HTTP COM object - @error = " & @error) With $oHttp ;Open POST request, set request header(s), and send the request .Open("POST", "https://jsonplaceholder.typicode.com/posts") If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.WinDescription)) .SetRequestHeader("Content-Type", "application/json") .Send($POST_DATA) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("(0x%X) %s", $oComErr.RetCode, $oComErr.Description)) ConsoleWrite(StringFormat("HTTP Status: %s %s", .Status, .StatusText) & @CRLF) ;If http status code not 201, exit with message If .Status <> 201 Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", StringFormat("HTTP Status Code = %s %s", .Status, .StatusText)) ;Display response ConsoleWrite(@CRLF & "HTTP Response:" & @CRLF) ConsoleWrite(.ResponseText & @CRLF) EndWith EndFunc Func com_error_handler($oError) With $oError ConsoleWrite(@ScriptName & " (" & .scriptline & ") : ==> COM Error intercepted !" & @CRLF) ConsoleWrite(@TAB & "Error Number........... " & "0x" & Hex(.number) & @CRLF) ConsoleWrite(@TAB & "Error WinDescription... " & StringStripWS(.windescription, $STR_STRIPTRAILING) & @CRLF) ConsoleWrite(@TAB & "Error Description...... " & StringStripWS(.description , $STR_STRIPTRAILING) & @CRLF) ConsoleWrite(@TAB & "Error ScriptLine....... " & .scriptline & @CRLF) ConsoleWrite(@TAB & "Error RetCode.......... " & "0x" & Hex(.retcode) & @CRLF) EndWith Return ; Return so @error can be trapped by the calling function EndFunc1 point -
Select Default profile from listview in User Profiles Window - (Moved)
argumentum reacted to CassidyHunt for a topic
Awesome. Thank you for the clue. Got it going.1 point -
Select Default profile from listview in User Profiles Window - (Moved)
CassidyHunt reacted to argumentum for a topic
use ControlListView()1 point -
[New Version] - 30 Mar 21 Added: - _GUIExtender_EventMonitor now returns 0 if nothing has occurred and 1 if a section has been actioned. @extended is set to the index number of the actioned section or 0 for all sections. This could be useful if you want to have only one section extended at one time - as soon as one is opened you can programmatically retract all the others. - The action control for a section can now be a normal button, a push button, an icon, or an image. Icons and images are passed as full paths. Normally the main icon of an exe/DLL file is shown, but this can be changed by adding the icon index number separated from the path by "|". See the _GUIExtender_Section_Activate header for more details. New UDF plus examples in the zip in the first post. M231 point
-
Send("{CAPSLOCK off}") does not work?
Decibel reacted to jvanegmond for a topic
Opt SendCapslockMode Specifies if AutoIt should store the state of capslock before a Send function and restore it afterwards. 0 = don't store/restore 1 = store and restore (default)1 point