Leaderboard
Popular Content
Showing content with the highest reputation on 08/05/2025 in all areas
-
JSON UDF in pure AutoIt
WildByDesign and one other reacted to SOLVE-SMART for a topic
Here a example how you can do it with jq directly instead of using the JSON.au3 UDF. Don't get me wrong, I like the JSON library (UDF) from @AspirinJunkie - he already knows that. I simply try to give you another perspective how you can handle a JSON file with a widespread (AutoIt independent) library. In case you want to stick with AutoIt, no problem, use the JQ adaption of @TheXman who creates this lovely json-processor. Best regards Sven2 points -
JSON UDF in pure AutoIt
WildByDesign and one other reacted to TheDcoder for a topic
You'll have to parse the array first and then manually insert the correct index into your commands. If you want to do it in a "cleaner" way, you can just modify the Array in AutoIt and insert the whole thing back with your changes.2 points -
2 points
-
_SectionsArrays A library for reading, writing, and managing 1D or 2D arrays, stored in a single text file using a section-based format. It provides functions to easily handle data, update existing sections, or add new ones. ; ; https://www.autoitscript.com/forum/topic/213059-_sectionsarrays/ ;--------------------------------------------------------------------------------------- ; Title...........: _SectionsArrays ; Description.....: A library for reading, writing, and managing 1D or 2D arrays, ; stored in a single text file using a section-based format. ; It provides functions to easily handle data, update existing sections, or add new ones. ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 0.3 ; Note............: Testet in Win10 22H2 ;--------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sArraysFilepath = @ScriptDir & "\arrays.txt" If Not FileExists($sArraysFilepath) Then _MakeArrays($sArraysFilepath) If @error Then ConsoleWrite("_MakeArrays @error=" & @error & @CRLF) Local $aSections = _ArraysFromFile($sArraysFilepath) If @error Then ConsoleWrite("_ArraysFromFile @error=" & @error & @CRLF) ShellExecute($sArraysFilepath) Sleep(500) _ArraysDisplay($aSections, "Array Sections") EndFunc ;==>Example Func _MakeArrays($sFilePath) ; Make examples arrays ; Prepare Sections array Local $aSections[1][2] $aSections[0][0] = 0 Local $Info ; "Monthly zoo Report" array Local $Array[][] = [ _ ["Month", "Bears", "Dolphins", "Whales"], _ ["jan", 8, 150, 80], _ ["feb", 54, 77, 54], _ ["mar", 93, 32, 10], _ ["apr", 116, 11, 76], _ ["may", 137, 6, 93], _ ["jun", 184, 1, 72]] ; Add array to Sections array $Info = _AddArrayToArrays($aSections, "Monthly zoo Report", $Array) ConsoleWrite("add $Info=" & $Info & @CRLF) ; "Base Items" array Local $aArray_Base[2][2] = [["Item 0 - 0", "Item 0 - 1"], ["Item 1 - 0", "Item 1 - 1"]] ; Add array to Sections array $Info = _AddArrayToArrays($aSections, "Base Items", $aArray_Base) ConsoleWrite("add $aArray_Base=" & $Info & @CRLF) ; "item Index" array Local $aIndex[10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ; Add array to Sections array $Info = _AddArrayToArrays($aSections, "item Index", $aIndex) ConsoleWrite("add $aIndex=" & $Info & @CRLF) ; "item Index2" array Local $aIndex2[1][10] = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] $Info = _AddArrayToArrays($aSections, "item Index2", $aIndex2) ConsoleWrite("add $aIndex2=" & $Info & @CRLF) ; Save arrays to file _ArraysToFile($sFilePath, $aSections) EndFunc ;==>_MakeArrays ;-------------------------------------------------------------------------------------------------------------------------------- ; Help functions (A library for reading, writing, and managing 1D or 2D arrays, stored in a single text file using a section-based format.) ;-------------------------------------------------------------------------------------------------------------------------------- Func _ArraysDisplay(ByRef $aItems, $sTitle = "") ; Creates a GUI window to display and browse the contents of multiple arrays. Local $hGUI = GUICreate($sTitle, 300, 200, -1, -1, $WS_OVERLAPPEDWINDOW) Local $idListview = GUICtrlCreateListView("Sections | Arrays", 0, 0, 300, 200, $LVS_SINGLESEL) GUICtrlSetFont(-1, 10) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_SetColumnWidth($idListview, 0, 170) _GUICtrlListView_SetColumnWidth($idListview, 1, 120) GUISetState(@SW_SHOW) Local $aIdItems[UBound($aItems, 1)] If @error Then Return SetError(@error, 0, 0) $aIdItems[0] = $aItems[0][0] For $i = 1 To $aIdItems[0] Local $sLabel = "error" Local $aArray = $aItems[$i][1] If IsArray($aArray) Then Local $iDimension = UBound($aArray, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional. Local $sDim = "" For $d = 1 To $iDimension $sDim &= "[" & UBound($aArray, $d) & "]" Next $sLabel = "Array" & $sDim EndIf $aIdItems[$i] = GUICtrlCreateListViewItem($aItems[$i][0] & " | {" & $sLabel & "}", $idListview) Next Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_RESIZED Local $iWH = WinGetClientSize($hGUI) GUICtrlSetPos($idListview, 0, 0, $iWH[0], $iWH[1]) Case $aIdItems[1] To $aIdItems[$aIdItems[0]] Local $id = $iMsg - $aIdItems[1] + 1 $aArray = $aItems[$id][1] _ArrayDisplay($aArray, $aItems[$id][0]) EndSwitch WEnd GUIDelete() EndFunc ;==>_ArraysDisplay ;-------------------------------------------------------------------------------------------------------------------------------- Func _AddArrayToArrays(ByRef $aArrays, $sName, $aNewArray) ; Adds a new array to the main array structure, or updates an existing one. Local $iCurrentSections = $aArrays[0][0] ; Check if the section name already exists For $i = 1 To $iCurrentSections If $aArrays[$i][0] = $sName Then ; Section exists, update the array $aArrays[$i][1] = $aNewArray Return True EndIf Next ; Section does not exist, add a new one ReDim $aArrays[$iCurrentSections + 2][2] ; Add the new section name and the array $aArrays[$iCurrentSections + 1][0] = $sName $aArrays[$iCurrentSections + 1][1] = $aNewArray ; Update the total number of sections count $aArrays[0][0] = $iCurrentSections + 1 Return True EndFunc ;==>_AddArrayToArrays ;-------------------------------------------------------------------------------------------------------------------------------- Func _ArraysToFile($sFilePath, $aArrays, $sDelim_Col = "|") ; Saves a multi-array structure back to a text file. Local $sOutput = "" Local $iNumSections = $aArrays[0][0] ; Loop through each section For $i = 1 To $iNumSections Local $sSectionName = $aArrays[$i][0] Local $aCurrentArray = $aArrays[$i][1] ; Get the array dimension Local $iDimension = UBound($aCurrentArray, $UBOUND_DIMENSIONS) ; Append the section name with the dimension to the output string $sOutput &= "[" & $sSectionName & "]" & $iDimension & "D" & @CRLF ; Convert the array to a string Local $sArrayString = _ArrayToString($aCurrentArray, $sDelim_Col) ; Append the array string to the output, followed by a newline $sOutput &= $sArrayString & @CRLF & @CRLF Next Local $hFile = FileOpen($sFilePath, $FO_OVERWRITE + $FO_UTF8_NOBOM) If $hFile = -1 Then Return SetError(1, 0, False) EndIf FileWrite($hFile, $sOutput) FileClose($hFile) Return True EndFunc ;==>_ArraysToFile ;-------------------------------------------------------------------------------------------------------------------------------- Func _RemoveArraySection(ByRef $aArrays, $sName) ; Removes a section and its corresponding array from the main array structure. Local $iCurrentSections = $aArrays[0][0] ; Check if the section name exists For $i = 1 To $iCurrentSections If $aArrays[$i][0] = $sName Then _ArrayDelete($aArrays, $i) $aArrays[0][0] = $iCurrentSections - 1 ReDim $aArrays[$iCurrentSections][2] Return True EndIf Next Return False ; Section not found EndFunc ;==>_RemoveArraySection ;-------------------------------------------------------------------------------------------------------------------------------- Func _ArraysFromFile($sFilePath, $sDelim_Col = "|") ; Reads a text file containing multiple sections and converts them into a 2D array structure. Local $sFileTxt = FileRead($sFilePath) If @error Then Return SetError(1, 0, "") ; Put a @CRLF in start, and convert all @LF, @CR to @CRLF $sFileTxt = @CRLF & StringRegExpReplace($sFileTxt, "(\r\n|\n)", @CRLF) ; split String in (@CRLF & "[") Local $aPart = StringSplit($sFileTxt, @CRLF & "[", 1) If $aPart[0] < 2 Then Return SetError(2, 0, "") Local $aSections[$aPart[0]][2] $aSections[0][0] = $aPart[0] - 1 For $i = 2 To $aPart[0] ; normal first line is the (name & ]) Local $iPos = StringInStr($aPart[$i], "]", 0, -1) If Not $iPos > 0 Or @error Then Return SetError(3, 0, "") ; find the name and the Dimension Local $sName = StringLeft($aPart[$i], $iPos - 1) Local $iDimension = 0 + Number(StringMid($aPart[$i], $iPos + 1, 1)) If Not ($iDimension = 1 Or $iDimension = 2) Then Return SetError(4, 0, "") ; remove leading CRLF or LF from front & back Local $sString = StringRegExpReplace(StringTrimLeft($aPart[$i], $iPos + 2), '(^[\r\n]+|[\r\n]+$)', '') Local $aArrayFromText ; $iDimension - 1 to $bForce2D => true $aArrayFromText = _ArrayFromString($sString, $sDelim_Col, Default, $iDimension - 1) $aSections[$i - 1][0] = $sName $aSections[$i - 1][1] = $aArrayFromText Next Return $aSections EndFunc ;==>_ArraysFromFile ;-------------------------------------------------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much1 point
-
JSON UDF in pure AutoIt
WildByDesign reacted to argumentum for a topic
..and a question unrelated to the thread should go in a help area instead of taking one over. Ditto.1 point -
JSON UDF in pure AutoIt
SOLVE-SMART reacted to WildByDesign for a topic
Thank you. I am a complete rookie with this UDF. I think that your "cleaner" way sounds like my best option. I do have the JSON loaded with the _JSON_Parse() function. Does that make the json array available in AutoIt already in some way or do I need to do something else to access it as an array? Thank you for your suggestion and example as well, Sven. I really appreciate it. I was not familar with jq before but I can understand the power and beauty of it because I am familiar with sed, awk and grep. I can see myself using jq for my own purposes. But not so much for this project because it will be a single binary on other users' systems and, in those scenarios, I try my best not to drop any additional binaries on disk whenever possible.1 point -
_SectionsArrays
Musashi reacted to argumentum for a topic
;Local $aIndex[10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Local $aIndex[1][10] = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] It'd be nice to do something to differentiate between 1D and 2D. Tho this is the only scene where it would not conform to recreate the original array 🤔 Thanks for sharing Edit: ; split String in (@CRLF & @CRLF & "{") ; for 1D ? ; split String in (@CRLF & @CRLF & "[") ; for 2D ?, and yes I added a 2nd @CRLF Edit2: or, add what it is to it, like: [my array 1D] or [my array 2D] just as an internal indicator ?1 point -
DwmColorBlurMica
argumentum reacted to WildByDesign for a topic
Version 1.1.3 has been added to the first post. As usual, detailed release notes are also updated on the first post with each release. The main highlight of this release is adding a 1-click option to patch all VSCode/VSCodium install locations on the system to allow for backdrop materials to be applied. Modified files are backed up and restored if/when you choose to do so. Those files get restored with each VSCode/VSCodium update also. Therefore, patching is required with each VSCode/VSCodium update. The entire GUI has been made draggable as well since there is space to do so and also because some of the backdrop materials can make it hard to tell where the titlebar is anyway. Also some nice bug fixes in this release. Next release, I will try to make a 1-click patch to patch Windows Terminal settings.json file so that users do not have to do it manually.1 point -
AutoIt error getting current time?
Trong reacted to argumentum for a topic
#include <WinApi.au3> GUIRegisterMsg($WM_TIMECHANGE, _WM_TIMECHANGE) Func _WM_TIMECHANGE($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite('> >>> WM_TIMECHANGE' & @CRLF) EndFunc @Trong, the above triggers when the time zone changes. Maybe you can reload if the unlikely possibility that it ( the time zone ) changes, for now, until the next version is released.1 point -
1 point
-
You have to handle the WM_SIZE message yourself unfortunately, and then use ControlMove (Or MoveWindow as I have). This means doing all the maths yourself as well, as you don't get the easy to use resizing flags. This is a simple case with a 2px border on all sides, so the maths wasn't hard. #include<GUIRichEdit.au3> #include<WindowsConstants.au3> #include<EditConstants.au3> #include<WinAPI.au3> Global $hGUI = GUICreate("Testing WM_SIZE", 350, 250, -1, -1, BitOR($WS_THICKFRAME, $WS_POPUP, $WS_CAPTION, $WS_SYSMENU)) Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "This is a test.", 2, 2, 346, 246, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUISetState() While True $iMsg = GUIGetMsg() Select Case $iMsg = -3 _GUICtrlRichEdit_Destroy($hRichEdit) GUIDelete() Exit EndSelect WEnd Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) Local $iWidth = _WinAPI_LoWord($lParam) Local $iHeight = _WinAPI_HiWord($lParam) _WinAPI_MoveWindow($hRichEdit, 2, 2, $iWidth - 4, $iHeight - 4) Return 0 EndFunc ;==>WM_SIZE1 point
-
Is there a way to check if a URL exists without calling it?
hudsonhock reacted to Jos for a topic
Works fine for me... Try this version to see what the problem with the Com object is.. ;Check existance of a URL ;adapted to AutoIt from http://www.developerfusion.co.uk/show/1605/ ;by DaleHohm ;Timeout values in milliseconds $ResolveTimeout = 500 $ConnectTimeout = 500 $SendTimeout = 500 $ReceiveTimeout = 500 ; Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") $sTestUrl = "http://www.microsoft.com/nonexistingpage.html" ; With $oHttpRequest .SetTimeouts ($ResolveTimeout, $ConnectTimeout, $SendTimeout, $ReceiveTimeout) .Open ("GET", $sTestUrl) .Send Select Case .Status = 200;No problem! ConsoleWrite($sTestUrl & " is a valid, available URL" & @CR) Case .Status = 404;Not found ConsoleWrite($sTestUrl & " could not be found (404 Error)" & @CR) Case Else;Some other problem ConsoleWrite("An unexpected HTTP Status value was returned: " & .Status & @CR) EndSelect EndWith ; $oHttpRequest = "" ; ; Com Error Handler Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) $oMyRet[0] = $HexNumber $oMyRet[1] = StringStripWS($oMyError.description,3) ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF) SetError(1); something to check for when this function returns Return EndFunc ;==>MyErrFunc1 point -
Is there a way to check if a URL exists without calling it?
hudsonhock reacted to DaleHohm for a topic
Sure -- this should work... ;Check existance of a URL ;adapted to AutoIt from http://www.developerfusion.co.uk/show/1605/ ;by DaleHohm ;Timeout values in milliseconds $ResolveTimeout = 500 $ConnectTimeout = 500 $SendTimeout = 500 $ReceiveTimeout = 500 $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") If $oHttpRequest = 0 Then ConsoleWrite("Error creating Object $oHttpRequest. " & _ "You must have 3.0 or later of the MSXML library to use this code" & @CR) EndIf $sTestUrl = "http://www.microsoft.com/nonexistingpage.html" With $oHttpRequest .SetTimeouts ($ResolveTimeout, $ConnectTimeout, $SendTimeout, $ReceiveTimeout) .Open ("GET", $sTestUrl) .Send Select Case .Status = 200;No problem! ConsoleWrite($sTestUrl & " is a valid, available URL" & @CR) Case .Status = 404;Not found ConsoleWrite($sTestUrl & " could not be found (404 Error)" & @CR) Case Else;Some other problem ConsoleWrite("An unexpected HTTP Status value was returned: " & .Status & @CR) EndSelect EndWith $oHttpRequest = "" Enjoy, Dale Edit: Added check object creation and caveat about MSXML 3.01 point