Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/23/2023 in all areas

  1. https://github.com/MicrosoftEdge/WebView2Announcements/issues/61
    2 points
  2. This UDF brings the power and flexibility of jq to AutoIt scripts. jq is an open-source, powerful, and flexible command-line based JSON processor. As it says on their website, jq is like 'sed' for JSON. jq can be used for the simplest of tasks like retrieving JSON objects and values (parsing), to very advanced JSON processing using its numerous built-in functions and conditional processing. Its built-in functions can handle math, selection, conditional processing, mapping, object and array manipulation, flattening, reduction, grouping, and much more. You can even create your own jq functions. You can learn more about jq and even play with it in real-time, using jq's online jq playground, all on their website. Here and some helpful links to get you more familiar with jq, what can be done with it, its built-in functions, and its syntax. jq Website: https://jqlang.github.io/jq/ jq Manual: https://jqlang.github.io/jq/manual/ jqWiki (FAQ, Cookbook, Advanced Topics) https://github.com/jqlang/jq/wiki jq is a single 32 or 64 bit executable that has no other dependencies. Just like using the SQLite UDF, the only requirement to use this UDF is that the jq executable reside in a location in which the UDF can execute it. The latest win32 & win64 versions have been included in the UDF download. You can always get newer versions from the jq website. jq at a high level Like 'sed', jq reads JSON in, either through STDIN or one or more files, processes it thru one or more "filters", and outputs the results. You can, optionally, supply "options" that affect how it reads the input, where it gets its "filters", and how it writes its output. It looks a little like this: JSON ---> jq processor (using supplied filters and options) ---> Output So in jq lingo, you basically use "Filters" to tell jq what you want it to do. So in the UDF file, that is why the main functions ( _jqExec() and _jqExecFile() ) refer to filters and options. Please make note that jq works with relatively strict JSON. This means that all JSON read must be conform to the standard. Luckily, jq is pretty good at identifying where a format error exists in non standard JSON. The jq UDF There are 2 main funtions in the UDF file, _jqExec and jqExecFile. With these 2 functions, you can pretty much do anything that jq can do. The only difference between to two functions is whether the JSON is supplied by a string or a file. The 2 primary functions simply call the jq executable with the supplied information, after properly formatting the parameters. There are additional functions in the UDF to easily pretty-print your json, compact-print your json, dump the json data with its associated paths, and see if specific JSON keys exist, but they all just execute the _jqExec or _jqExecFile function with the proper filter. There are also a couple of extra functions to display what version of the UDF and jq executable you are currently using. There are also a couple of functions to enable and disable logging of jq information for debugging purposes. Most of the jq UDF file functions return an @error if unsuccessful. Some also include @extended info. Please see the actual function headers for more information on their usage and return values. The 2 primary functions below just format your jq request and pass it on the jq executable. The functions will also properly escape double quotes (") that are used in the filter. For most simple tasks, you just need to supply the JSON source and a filter. _jqExec($sJson, $sFilter, $sOptions = Default, $sWorkingDir = Default) Or _jqExecFile($sJsonFile, $sFilter, $sOptions = Default, $sWorkingDir = Default) Using jq in your script As stated earlier, the jq executable must reside somewhere where the script can locate and execute it. The _jqInit() function always has to be executed before any jq processing occurs. _jqInit() merely locates the executable or uses the supplied path. It also clears any previous debug log. The jq UDF folder contains a jq example script that has several examples to how to do some of the most common JSON processing tasks. Here are a few examples to get you started: How to pretty-print some JSON #include "jq.au3" ;_jqInit is only needed if the jq executale is not in the PATH or @ScriptDir _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"fruits":[{"Apple":{"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqPrettyPrintJson($sJson) ConsoleWrite(@CRLF & "Pretty-Print JSON" & @CRLF & $sCmdOutput & @CRLF) How to compact-print some JSON #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{ "fruits" : [{"Apple" : {"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqCompactPrintJson($sJson) ConsoleWrite(@CRLF & "Compact-Print JSON" & @CRLF & $sCmdOutput & @CRLF) Dump JSON data (paths and values) #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{ "fruits" : [{"Apple" : {"color":"Red","season":"Fall"}}, {"Banana":{"color":"Yellow","season":"Summer"}}]}' $sCmdOutput = _jqDump($sJson) ConsoleWrite(@CRLF & "Dump JSON paths and values" & @CRLF & $sCmdOutput & @CRLF) How to GET JSON values #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple" : {"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana.color' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Get color of banana" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) or #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple" : {"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = 'getpath(["Banana", "color"])' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Get color of banana" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) Check for the existence of a key #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red","season":"Fall"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana | has("color")' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Check for existence of color key within Banana object" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) Count of how many Items in an object #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = '.Banana | length' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("How many items in the Banana object" & @CRLF) ConsoleWrite("Input: : " & _jqCompactPrintJson($sJson) & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) How to PUT/Create/Modify JSON #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sInput = "" $sFilter = 'setpath(["Apple","color"];"Red") | setpath(["Banana","color"];"Yellow") | setpath(["Banana","season"];"Summer")' $sOptions = '-n' ;required if no input supplied $sCmdOutput = _jqExec($sInput, $sFilter, $sOptions) ConsoleWrite("Update/Create JSON" & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & @CRLF & $sCmdOutput & @CRLF) List all of the fruits (top-level keys) #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '{"Apple":{"color":"Red"}, "Banana":{"color":"Yellow","season":"Summer"}}' $sFilter = 'keys | .[]' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("List all top-level keys (fruits)" & @CRLF) ConsoleWrite("Input : " & $sJson & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & @CRLF & $sCmdOutput & @CRLF) Calculate the sum of all of the objects' price * qty #include "jq.au3" ;Initialize jq environment _jqInit() If @error Then Exit ConsoleWrite("ERROR: Unable to initialize jq - @error = " & @error & @CRLF) $sJson = '[{"id":1,"price":20.00,"qty":10},{"id":2,"price":15.00,"qty":20.25},{"id":3,"price":10.50,"qty":30}]' $sFilter = 'map(.price * .qty) | add' $sCmdOutput = _jqExec($sJson, $sFilter) ConsoleWrite("Calculate the sum of all of the objects' price * qty" & @CRLF) ConsoleWrite("Input : " & $sJson & @CRLF) ConsoleWrite("Filter : " & $sFilter & @CRLF) ConsoleWrite("Output : " & $sCmdOutput & @CRLF) The examples above, and the ones in the example files, merely scratch the surface of what jq can do. It may look intimidating at first but it really isn't that bad once you start playing with it. You can find several more examples and play around with them or create your own using jqPlayground. jqPlayground is a separate, stand alone, interactive tool for creating, testing and learning JSON processing using jq. If you have any questions regarding the UDF, or how to perform a certain task using jq, I'll try my best to answer them. Since jq has been around for a while now, there's also several jq-related questions and answers on StackOverflow. >>> Download the UDF in the Files Section <<<
    1 point
  3. Version v1.4.0

    827 downloads

    Purpose (from Microsoft's website) The HTTP Server API enables applications to communicate over HTTP without using Microsoft Internet Information Server (IIS). Applications can register to receive HTTP requests for particular URLs, receive HTTP requests, and send HTTP responses. The HTTP Server API includes SSL support so that applications can exchange data over secure HTTP connections without IIS. Description There have been several times in the past that I wanted to either retrieve information from one of my PCs or execute commands on one of my PCs, whether it was from across the world or sitting on my couch. Since AutoIt is one of my favorite tools for automating just about anything on my PC, I looked for ways to make to make it happen. Setting up a full blown IIS server seemed like overkill so I looked for lighter weight solutions. I thought about creating my own AutoIt UDP or TCP server but that just wasn't robust enough, Then I found Microsoft's HTTP Server API and it looked very promising. After doing a little research into the APIs, I found that it was flexible & robust enough to handle just about any of the tasks that I required now and in the future. So a while back I decided to wrap the API functionality that I needed into an AutoIt UDF file to allow me to easily create the functionality I needed at the time. It has come in very handy over the years. Of course it wasn't all wrapped up with a nice little bow like it is now. That only happened when I decided to share it with anyone else who could use it or learn from it. The example file that I included is a very granular example of the steps required to get a lightweight HTTP Server up and listening for GET requests. The UDF is a wrapper for the Microsoft APIs. That means to do anything over and above what I show in the example, one would probably have to have at least a general knowledge of APIs or the ability to figure out which APIs/functions to use, what structures and data is needed to be passed to them, and in what order. However, the UDF gives a very solid foundation on which to build upon. Of course, if anyone has questions about the UDF or how to implement any particular functionality, I would probably help to the extent that I could or point you in the right direction so that you can figure out how to implement your own solution. The APIs included in the UDF are the ones that I needed in the past to do what I needed to do. If any additional APIs need to be added to the UDF file, please make those suggestions in the related forum topic. Being that this is basically an AutoIt wrapper for the Microsoft API functions, there's no need to create AutoIt-specific documentation. All of the UDF functions, structures, constants, and enumerations are named after their Microsoft API counterparts. Therefore, you can refer to Microsoft's extensive documentation of their HTTP Server API. As stated earlier, if there is one or more APIs that you find yourself needing for your particular solution, please suggest it in the related Example Scripts forum topic. Related Links Microsoft HTTP Server API - Start Page Microsoft HTTP Server API - API v2 Reference Microsoft HTTP Server API - Programming Model
    1 point
  4. water

    AutoIt Cheat Sheet

    I tried to update the tutorial but noticed that The information in the Operators section is just a duplication of the help file The tables are badly formatted (by using HTML and not the wiki markups), other formatting is comkpletely wrong (e.g. precedence of operators) The coding of the examples do not adhere to the standards (hungarian notation etc.) described in other tutorials last but not least: The tutorial is described as "cheat sheet" If I find some spare time I will Remove duplicated information. The help file is the bible of AutoIt. As we do not want to update information in multiple places I will just insert a link to the help file. Update the examples so they adhere to our standards Update formatting What do you think?
    1 point
  5. SOLVE-SMART

    AutoIt Cheat Sheet

    As always, a valuable assessment from you @water, even if it's only 2 cents 😁 . I could change the color of this section/block (it's now a red one) and I could add a description ✔ . Thank you @water 🤝 . Best regards Sven
    1 point
  6. water

    AutoIt Cheat Sheet

    My 2 cents worth Au3Check and Au3Stripper are extra utilities to enhance coding. I would describe them in a separate section (if possible with a different color) and add a description to the block of each tool like "Au3Check - Checks the script for syntax errors". So coders can distinguish between the core language and extra tools.
    1 point
  7. 1 point
  8. @mLipokI imagine that you could do it, but I'm unsure if there's any real benefit. You may want to take a look at the Webdriver BiDi implementation, which includes many low level routines including event listeners.
    1 point
  9. Hey Melba, I'm using the latest version (19 Nov 21) on AutoIt 3.3.16.0. I added this to a script that doesn't have an AutoIt GUI involved and hit a small nuisance. I dug into it and found that it's because none of the chained #include <ExtMsgBox.au3> have any references to $SS_LEFT, $SS_CENTER, $SS_RIGHT for use as the 2nd parameter ($iJust) of _ExtMsgBoxSet(). I prefer using constants for readability, and these are referenced as being allowed. Did you put that in there just to see if anyone reads the docs? 🤓 Possible solutions are these in my recommended order: Remove the mention of $SS_LEFT, $SS_CENTER, $SS_RIGHT from the _ExtMsgBoxSet() function header in ExtMsgBox.au3 (I.e. Delete line 98), and from being used your ExtMsgBox_Example_1.au3 and ExtMsgBox_Example_3.au3. Add #include <StaticConstants.au3> to ExtMsgBox.au3. I'm currently adding this as an #include to my scripts beneath ExtMsgBox.au3 as you did in Examples 1 & 3. Add $SS_LEFT, $SS_CENTER, $SS_RIGHT as Global Const in ExtMsgBox.au3. It's messy using the same names that exist elsewhere though. Not a big deal, but if you're looking to post an updated version any time soon this might help some others from hitting this bump. I got lucky with the first script that I used your UDF with because I had #include <GUIConstants.au3> in it, which includes StaticConstants.au3 so everything "just worked." Thanks for this UDF!
    1 point
  10. There seems to be many way to achieve something like you're looking for, thanks to this nice and experienced community 👍 . Nevertheless I want to show you @taurus905 a quick example of a custom title bar which I created out of GUI snippets that I used in other projects before. 💡 Please keep in mind, I usually would modularize the code into separate files (depending on the duties), but in this case I just did it in a single script file. #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Au3Stripper=y #AutoIt3Wrapper_UseUpx=n #Au3Stripper_Parameters=/sf /sv /mo /rm /rsln #include-once #include <GUIConstants.au3> #include <Misc.au3> Global $mGui[], $mTitleBar[] Global $mClosingCrossIcon[], $mMinimizeIcon[] Global $mTitleBarColor[] $mTitleBarColor.background = 0xD9534F $mTitleBarColor.font = 0xFBEDED $mTitleBarColor.faviconIcon = $GUI_BKCOLOR_TRANSPARENT $mTitleBarColor.hoverMinimize = 0xE5E5E5 $mTitleBarColor.hoverClose = 0xE81123 _Actions() Func _Actions() _CreateGui() _CreateTitleBar() _AddTitleBarButtons() _ShowGui() _GuiEventListener() EndFunc Func _CreateGui() $mGui.Width = 600 $mGui.Height = 350 $mGui.Style = $WS_POPUP $mGui.Handle = GUICreate('', $mGui.Width, $mGui.Height, Default, Default, $mGui.Style) EndFunc Func _CreateTitleBar() ; background $mTitleBar.X = 0 $mTitleBar.Y = 0 $mTitleBar.W = ($mGui.Width - 137) $mTitleBar.H = 26 $mTitleBar.ButtonWidth = 25 $mTitleBar.ButtonHeight = $mTitleBar.ButtonWidth $mTitleBar.cId = GUICtrlCreateLabel('', $mTitleBar.X, $mTitleBar.Y, $mTitleBar.W, $mTitleBar.H) GUICtrlSetBkColor($mTitleBar.cId, $mTitleBarColor.background) GUICtrlSetStyle($mTitleBar.cId, -1, $GUI_WS_EX_PARENTDRAG) ; favicon icon GUICtrlCreateLabel('🎲', 4, 5.5) ; I used the cube icon as example which can be pasted in by pressing [WIN] + [.] GUICtrlSetBkColor(-1, $mTitleBarColor.faviconIcon) GUICtrlSetFont(-1, 11) ; title GUICtrlCreateLabel('GUI with custom title bar', 24, 5.5, ($mGui.Width / 2)) GUICtrlSetColor(-1, $mTitleBarColor.font) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 9) EndFunc Func _AddTitleBarButtons() _AddClosingCrossIcon() _AddMaximizeIcon() _AddMinimizeIcon() EndFunc Func _AddClosingCrossIcon() ; background $mClosingCrossIcon.X = ($mGui.Width - 45) $mClosingCrossIcon.Y = 0 $mClosingCrossIcon.W = $mTitleBar.ButtonWidth + 20 $mClosingCrossIcon.H = $mTitleBar.ButtonHeight + 1 $mClosingCrossIcon.cId = GUICtrlCreateLabel('', $mClosingCrossIcon.X, $mClosingCrossIcon.Y, $mClosingCrossIcon.W, $mClosingCrossIcon.H) GUICtrlSetBkColor($mClosingCrossIcon.cId, $mTitleBarColor.background) ; icon GUICtrlCreateLabel(ChrW(0xCD), ($mGui.Width - 31), 5.5, $mTitleBar.ButtonWidth, $mTitleBar.ButtonHeight) GUICtrlSetFont(-1, 14, 100, Default, 'Wingdings 2') GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) EndFunc Func _AddMaximizeIcon() ; background GUICtrlCreateLabel('', ($mGui.Width - 92), 0, $mTitleBar.ButtonWidth + 22, $mTitleBar.ButtonHeight + 1) GUICtrlSetBkColor(-1, $mTitleBarColor.background) ; icon GUICtrlCreateLabel(ChrW(0xA3), ($mGui.Width - 75), 6.5, $mTitleBar.ButtonWidth, $mTitleBar.ButtonHeight) GUICtrlSetFont(-1, 11, 100, Default, 'Wingdings 2') GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xCCCCCC) EndFunc Func _AddMinimizeIcon() ; background $mMinimizeIcon.X = ($mGui.Width - 137) $mMinimizeIcon.Y = 0 $mMinimizeIcon.W = $mTitleBar.ButtonWidth + 20 $mMinimizeIcon.H = $mTitleBar.ButtonHeight + 1 $mMinimizeIcon.cId = GUICtrlCreateLabel('', $mMinimizeIcon.X, $mMinimizeIcon.Y, $mMinimizeIcon.W, $mMinimizeIcon.H) GUICtrlSetBkColor($mMinimizeIcon.cId, $mTitleBarColor.background) ; icon GUICtrlCreateLabel(ChrW(0x2015), ($mGui.Width - 119), 6.5, $mTitleBar.ButtonWidth, $mTitleBar.ButtonHeight) GUICtrlSetFont(-1, 8, 100, Default, 'Segoe UI') GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) EndFunc Func _ShowGui() GUISetState(@SW_SHOW, $mGui.Handle) EndFunc Func _GuiEventListener() AdlibRegister('_HoverActions', 100) Local Const $iGuiEventClose = -3 While True Switch GUIGetMsg() Case $iGuiEventClose, $mClosingCrossIcon.cId ExitLoop Case $mMinimizeIcon.cId GUISetState(@SW_MINIMIZE, $mGui.Handle) EndSwitch WEnd _GuiDisposeAndExit() EndFunc Func _GuiDisposeAndExit() AdlibUnRegister('_HoverActions') GUIDelete($mGui.Handle) Exit EndFunc Func _HoverActions() Local $aMouseData = MouseGetPos() Local $aGuiData = WinGetPos($mGui.Handle) If Not _HoverTitleBar($aMouseData, $aGuiData) Then _ResetHoverColor() Return EndIf Select Case _HoverMinimizeIcon($aMouseData, $aGuiData) GUICtrlSetBkColor($mMinimizeIcon.cId, $mTitleBarColor.hoverMinimize) GUICtrlSetBkColor($mClosingCrossIcon.cId, $mTitleBarColor.background) Case _HoverClosingCrossIcon($aMouseData, $aGuiData) GUICtrlSetBkColor($mClosingCrossIcon.cId, $mTitleBarColor.hoverClose) GUICtrlSetBkColor($mMinimizeIcon.cId, $mTitleBarColor.background) Case Else _ResetHoverColor() EndSelect EndFunc Func _ResetHoverColor() GUICtrlSetBkColor($mClosingCrossIcon.cId, $mTitleBarColor.background) GUICtrlSetBkColor($mMinimizeIcon.cId, $mTitleBarColor.background) EndFunc Func _HoverTitleBar($aMouseData, $aGuiData) Return _IsMouseOnControl( _ $aMouseData[0] - $aGuiData[0], _ $aMouseData[1] - $aGuiData[1], _ $mTitleBar.X, $mTitleBar.Y, $mGui.Width, $mTitleBar.H) EndFunc Func _HoverMinimizeIcon($aMouseData, $aGuiData) Return _IsMouseOnControl( _ $aMouseData[0] - $aGuiData[0], _ $aMouseData[1] - $aGuiData[1], _ $mMinimizeIcon.X, $mMinimizeIcon.Y, $mMinimizeIcon.W, $mMinimizeIcon.H) EndFunc Func _HoverClosingCrossIcon($aMouseData, $aGuiData) Return _IsMouseOnControl( _ $aMouseData[0] - $aGuiData[0], _ $aMouseData[1] - $aGuiData[1], _ $mClosingCrossIcon.X, $mClosingCrossIcon.Y, $mClosingCrossIcon.W, $mClosingCrossIcon.H) EndFunc Func _IsMouseOnControl($iXMouse, $iYMouse, $iXControl, $iYControl, $iWidthControl, $iHeightControl) If $iXMouse >= $iXControl And _ $iYMouse >= $iYControl And _ $iXMouse <= $iXControl + $iWidthControl And _ $iYMouse <= $iYControl + $iHeightControl Then Return True Else Return False EndIf EndFunc It was more complex than I thought, but as a proof of concept I enjoyed it 😅 . Please notice that you can minimize or close the GUI like you would expect it. Also the GUI is draggable by the title bar. 👓 Open the spoiler box to see the example: Best regards Sven
    1 point
  11. You are welcome.... and the lesson for today is: Don't assume anything and always check everything, both exact string content as the results of each performed function. Jos
    1 point
  12. I use the following MS sources to get the rules for the complexity check: https://technet.microsoft.com/en-us/library/hh994562(v=ws.10).aspx https://technet.microsoft.com/en-us/library/cc786468(v=ws.10).aspx
    1 point
  13. I have some scripts that use Excel to present the result of data validation tests and I was becoming a little frustrated at the length of time it was taking to write the data to excel, using _ExcelWriteSheetFromArray() function in the Excel.au3 UDF. So I thought I'd take a look and see if I could improve on it's performance. This was the result. This new function is 200 to 300 times faster than _ExcelWriteSheetFromArray() for large arrays (20000 plus elements) and in the region of 100 times faster for small arrays. I have also included the option to write only part of the array to the spreadsheet as sometimes I do not need all of the array. _ExcelSheetWriteFromArray ; #FUNCTION# ==================================================================================================================== ; Name...........: _ExcelSheetWriteFromArray ; Description ...: Writes a 2D array, or part of, to a specified location in the active worksheet ; Syntax.........: _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) ; Parameters ....: $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() ; $aArray - The array ByRef to write data from (array is not modified) ; $iExcelStartRow - The spreadsheet row to start writing the array to, default is 1 ; $iExcelStartCol - The spreadsheet column to start writing the array to, default is 1 ; $iArrayStartRow - Start row index of array to start writing data from, default is 0 ; $iArrayStartCol - Start column index of array to start writing data from, default is 0 ; $iArrayEndRow - End row index of array to stop writing data from, default is Ubound($aArray) ; $iArrayEndCol - End column index of array to stop writing data from, default is Ubound($aArray,2) ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error on errors: ; |@error=1 - Excel object does not exist ; |@error=2 - Not a 2D array ; |@error=3 - End row greater than start row ; |@error=4 - End col greater than start col ; Author ........: Bowmore ; Modified.......: ; Remarks .......: Only 2D arrays are currently handeled. Maxim cell content length is 255 characters ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) Local $iExcelEndRow = 1 Local $iExcelEndCol = 1 If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If UBound($aArray, 0) <> 2 Then Return SetError(2, 0, 0) If $iExcelStartRow = Default Then $iExcelStartRow = 1 If $iExcelStartCol = Default Then $iExcelStartCol = 1 If $iArrayStartRow = Default Then $iArrayStartRow = 0 If $iArrayStartCol = Default Then $iArrayStartCol = 0 If $iArrayEndRow = Default Then $iArrayEndRow = UBound($aArray) - 1 If $iArrayEndCol = Default Then $iArrayEndCol = UBound($aArray, 2) - 1 If $iExcelStartRow < 1 Then $iExcelStartRow = 1 If $iExcelStartCol < 1 Then $iExcelStartCol = 1 If $iArrayStartRow < 0 Then $iArrayStartRow = 0 If $iArrayStartCol < 0 Then $iArrayStartCol = 0 If $iArrayEndRow < $iArrayStartRow Then Return SetError(3, 1, 0) If $iArrayEndCol < $iArrayStartCol Then Return SetError(4, 1, 0) $iExcelEndRow = $iExcelStartRow + $iArrayEndRow - $iArrayStartRow $iExcelEndCol = $iExcelStartCol + $iArrayEndCol - $iArrayStartCol ; Check if only part of the array is to written to the speadsheet If $iArrayStartRow <> 0 Or $iArrayStartCol <> 0 Or $iArrayEndRow <> UBound($aArray) - 1 Or $iArrayEndCol = UBound($aArray, 2) - 1 Then ;Copy specified array range to a temporary array Local $aTemp[$iArrayEndRow - $iArrayStartRow + 1][$iArrayEndCol - $iArrayStartCol + 1] Local $iRow = 0 Local $iCol = 0 For $i = $iArrayStartRow To $iArrayEndRow $iCol = 0 For $j = $iArrayStartCol To $iArrayEndCol $aTemp[$iRow][$iCol] = $aArray[$i][$j] $iCol += 1 Next $iRow += 1 Next With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aTemp) EndWith Else With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aArray) EndWith EndIf EndFunc ;==>_ExcelSheetWriteFromArray Simple Speed Test _ExcelSheetWriteFromArray #include <excel.au3> Test_Main() Func Test_Main() Local $sXlsFile1 = @ScriptDir & "Test1.xls" Local $sXlsFile2 = @ScriptDir & "Test2.xls" Local $oExcel = 0 Local $Tim = 0 Local $aData[5000][10] For $i = 0 To 4999 $aData[$i][0] = "Y" $aData[$i][1] = "DATA_TEST_ROW_0" & StringFormat("%03i", $i) $aData[$i][2] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ultrices est varius elit consequat sollicitudin mollis libero ultrices. Quisque lobortis lorem quis nunc vestibulum tincidunt. Duis eget urna sapien, nec egestas purus. Fusce massa nunc." $aData[$i][3] = $i * 10 $aData[$i][4] = $i * 100 $aData[$i][5] = $aData[$i][3] / $aData[$i][4] $aData[$i][6] = "Pass" $aData[$i][7] = @YEAR & "-" & @MON & "-" & @MDAY & "T" & @HOUR & ":" & @MIN $aData[$i][8] = "FAIL" $aData[$i][9] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ultrices est varius elit consequat sollicitudin mollis libero ultrices. Quisque lobortis lorem quis nunc vestibulum tincidunt. Duis eget urna sapien, nec egestas purus. Fusce massa nunc." Next ; Speed Test of new function $oExcel = _ExcelBookNew(0) $Tim = TimerInit() _ExcelSheetWriteFromArray($oExcel, $aData) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($Tim) = ' & TimerDiff($Tim) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ExcelBookSaveAs($oExcel, $sXlsFile1) _ExcelBookClose($oExcel, 0, 0) ; Speed Test of old function $oExcel = _ExcelBookNew(0) $Tim = TimerInit() _ExcelWriteSheetFromArray($oExcel, $aData) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($Tim) = ' & TimerDiff($Tim) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _ExcelBookSaveAs($oExcel, $sXlsFile2) _ExcelBookClose($oExcel, 0, 0) EndFunc ;==>Test_Main ; #FUNCTION# ==================================================================================================================== ; Name...........: _ExcelSheetWriteFromArray ; Description ...: Writes a 2D array, or part of, to a specified location in the active worksheet ; Syntax.........: _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) ; Parameters ....: $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() ; $aArray - The array ByRef to write data from (array is not modified) ; $iExcelStartRow - The spreadsheet row to start writing the array to, default is 1 ; $iExcelStartCol - The spreadsheet column to start writing the array to, default is 1 ; $iArrayStartRow - Start row index of array to start writing data from, default is 0 ; $iArrayStartCol - Start column index of array to start writing data from, default is 0 ; $iArrayEndRow - End row index of array to stop writing data from, default is Ubound($aArray) ; $iArrayEndCol - End column index of array to stop writing data from, default is Ubound($aArray,2) ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error on errors: ; |@error=1 - Excel object does not exist ; |@error=2 - Not a 2D array ; |@error=3 - End row greater than start row ; |@error=4 - End col greater than start col ; Author ........: Bowmore ; Modified.......: ; Remarks .......: Only 2D arrays are currently handeled. Maxim cell content length is 255 characters ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ExcelSheetWriteFromArray($oExcel, ByRef $aArray, $iExcelStartRow = Default, $iExcelStartCol = Default, $iArrayStartRow = Default, $iArrayStartCol = Default, $iArrayEndRow = Default, $iArrayEndCol = Default) Local $iExcelEndRow = 1 Local $iExcelEndCol = 1 If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If UBound($aArray, 0) <> 2 Then Return SetError(2, 0, 0) If $iExcelStartRow = Default Then $iExcelStartRow = 1 If $iExcelStartCol = Default Then $iExcelStartCol = 1 If $iArrayStartRow = Default Then $iArrayStartRow = 0 If $iArrayStartCol = Default Then $iArrayStartCol = 0 If $iArrayEndRow = Default Then $iArrayEndRow = UBound($aArray) - 1 If $iArrayEndCol = Default Then $iArrayEndCol = UBound($aArray, 2) - 1 If $iExcelStartRow < 1 Then $iExcelStartRow = 1 If $iExcelStartCol < 1 Then $iExcelStartCol = 1 If $iArrayStartRow < 0 Then $iArrayStartRow = 0 If $iArrayStartCol < 0 Then $iArrayStartCol = 0 If $iArrayEndRow < $iArrayStartRow Then Return SetError(3, 1, 0) If $iArrayEndCol < $iArrayStartCol Then Return SetError(4, 1, 0) $iExcelEndRow = $iExcelStartRow + $iArrayEndRow - $iArrayStartRow $iExcelEndCol = $iExcelStartCol + $iArrayEndCol - $iArrayStartCol ; Check if only part of the array is to written to the speadsheet If $iArrayStartRow <> 0 Or $iArrayStartCol <> 0 Or $iArrayEndRow <> UBound($aArray) - 1 Or $iArrayEndCol = UBound($aArray, 2) - 1 Then ;Copy specified array range to a temporary array Local $aTemp[$iArrayEndRow - $iArrayStartRow + 1][$iArrayEndCol - $iArrayStartCol + 1] Local $iRow = 0 Local $iCol = 0 For $i = $iArrayStartRow To $iArrayEndRow $iCol = 0 For $j = $iArrayStartCol To $iArrayEndCol $aTemp[$iRow][$iCol] = $aArray[$i][$j] $iCol += 1 Next $iRow += 1 Next With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aTemp) EndWith Else With $oExcel.ActiveSheet .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).Select .Range(.Cells($iExcelStartRow, $iExcelStartCol), .Cells($iExcelEndRow, $iExcelEndCol)).value = $oExcel.Application.WorksheetFunction.Transpose($aArray) EndWith EndIf EndFunc ;==>_ExcelSheetWriteFromArray
    1 point
  14. Hello, I'm having a problem with _GDIPlus_BitmapCloneArea and then using _GDIPlus_GraphicsDrawImage to draw the cloned bmp to my graphics object. If i load an image from a file and clone that then its working correctly. If you run this code you'll see i'm getting a black box instead if the cloned image. Can anyone explain what i'm doing wrong? #include<GUIConstants.au3> #include <GDIPlus.au3> global $gui = GUICreate("BitmapCloneArea test", 500,500,-1,-1) GUISetState(@SW_SHOW) _GDIPlus_StartUp() $hBrush_dark = _GDIPlus_BrushCreateSolid(0xFF996633) $hBrush_light = _GDIPlus_BrushCreateSolid(0xFFFFFF99) $Graphics_obj = _GDIPlus_GraphicsCreateFromHWND($gui) _GDIPlus_GraphicsFillRect($Graphics_obj,0,0,500,250,$hBrush_dark) _GDIPlus_GraphicsFillRect($Graphics_obj,0,250,500,250,$hBrush_light) $bitmap_obj = _GDIPlus_BitmapCreateFromGraphics(500, 500, $Graphics_obj) ; Creates a Bitmap object based on a Graphics object, a width, and a height $bitmap_obj_clone = _GDIPlus_BitmapCloneArea($bitmap_obj,50,125,50,250,$GDIP_PXF32PARGB) ; Create a clone of a Bitmap object from the coordinates and format specified $bitmap_handle = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap_obj) ; Create a handle to a bitmap from a bitmap object $bitmap_obj2 = _GDIPlus_BitmapCreateFromHBITMAP($bitmap_handle) ; Create a Bitmap object from a bitmap handle _GDIPlus_ImageSaveToFile($bitmap_obj2, "testfile.bmp") _GDIPlus_GraphicsDrawImage($Graphics_obj, $bitmap_obj2, 100, 200) While 1 local $Msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit sleep(20) WEnd
    1 point
  15. The important lines are: $Graphics_obj = _GDIPlus_GraphicsCreateFromHWND($gui) $hBitmap = _GDIPlus_BitmapCreateFromGraphics(500, 500, $Graphics_obj) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) You can only draw directly with the default functions to a graphic handle but you cannot save a graphic handle to a bitmap directly. That is the reason why the $hBitmap and the $hBackbuffer is created. The _GDIPlus_ImageGetGraphicsContext() function will allow you to draw to the bitmap directly using the default function. Thus you can save the bitmap afterwards (don't mix it up with HBITMAPS (GDI)! To display the bitmap it needs to be copied to the graphic handle -> _GDIPlus_GraphicsDrawImage() 2nd benefit is when drawing animations it will not flicker. Br, UEZ
    1 point
  16. I tried a GIF file and a PNG file with transparency - same old problem. It saves transparent parts of image to black. Otherwise, it works well.
    1 point
×
×
  • Create New...