Leaderboard
Popular Content
Showing content with the highest reputation on 08/19/2020 in all areas
-
Introduction JSON (Javascript Object Notation) is a popular data-interchange format and supported by a lot of script languages. On AutoIt, there is already a >JSON UDF written by Gabriel Boehme. It is good but too slow, and not supports unicode and control characters very well. So I write a new one (and of course, fast one as usual). I use a machine code version of JSON parser called "jsmn". jsmn not only supports standard JSON, but also accepts some non-strict JSON string. See below for example. Important Update!! I rename the library from jsmn.au3 to json.au3. All function names are changed, too. Decoding Function Json_Decode($Json) $Json can be a standard or non-standard JSON string. For example, it accepts: { server: example.com port: 80 message: "this looks like a config file" } The most JSON data type will be decoded into corresponding AutoIt variable, including 1D array, string, number, true, false, and null. JSON object will be decoded into "Windows Scripting Dictionary Object" retuned from ObjCreate("Scripting.Dictionary"). AutoIt build-in functions like IsArray, IsBool, etc. can be used to check the returned data type. But for Object and Null, Json_IsObject() and Json_IsNull() should be used. If the input JSON string is invalid, @Error will be set to $JSMN_ERROR_INVAL. And if the input JSON string is not finish (maybe read from stream?), @Error will be set to $JSMN_ERROR_PART. Encoding Function Json_Encode($Data, $Option = 0, $Indent = "\t", $ArraySep = ",\r\n", $ObjectSep = ",\r\n", $ColonSep = ": ") $Data can be a string, number, bool, keyword(default or null), 1D arrry, or "Scripting.Dictionary" COM object. Ptr will be converted to number, Binary will be converted to string in UTF8 encoding. Other unsupported types like 2D array, dllstruct or object will be encoded into null. $Option is bitmask consisting following constant: $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) $JSON_UNESCAPED_UNICODE ; Encode multibyte Unicode characters literally $JSON_UNESCAPED_SLASHES ; Don't escape / $JSON_HEX_TAG ; All < and > are converted to \u003C and \u003E $JSON_HEX_AMP ; All &amp;amp;amp;s are converted to \u0026 $JSON_HEX_APOS ; All ' are converted to \u0027 $JSON_HEX_QUOT ; All " are converted to \u0022 $JSON_PRETTY_PRINT ; Use whitespace in returned data to format it $JSON_STRICT_PRINT ; Make sure returned JSON string is RFC4627 compliant $JSON_UNQUOTED_STRING ; Output unquoted string if possible (conflicting with $JSMN_STRICT_PRINT) Most encoding option have the same means like PHP's json_enocde() function. When $JSON_PRETTY_PRINT is set, output format can be change by other 4 parameters ($Indent, $ArraySep, $ObjectSep, and $ColonSep). Because these 4 output format parameters will be checked inside Jsmn_Encode() function, returned string will be always accepted by Jsmn_Decode(). $JSON_UNQUOTED_STRING can be used to output unquoted string that also accetped by Jsmn_Decode(). $JSON_STRICT_PRINT is used to check output format setting and avoid non-standard JSON output. So this option is conflicting with $JSON_UNQUOTED_STRING. Get and Put Functions Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) Json_Get(ByRef $Var, $Notation) These functions helps user to access object or array more easily. Both dot notation and square bracket notation can be supported. Json_Put() by default will create non-exists objects and arrays. For example: Local $Obj Json_Put($Obj, ".foo", "foo") Json_Put($Obj, ".bar[0]", "bar") Json_Put($Obj, ".test[1].foo.bar[2].foo.bar", "Test") Local $Test = Json_Get($Obj, '["test"][1]["foo"]["bar"][2]["foo"]["bar"]') ; "Test" Object Help Functions Json_ObjCreate() Json_ObjPut(ByRef $Object, $Key, $Value) Json_ObjGet(ByRef $Object, $Key) Json_ObjDelete(ByRef $Object, $Key) Json_ObjExists(ByRef $Object, $Key) Json_ObjGetCount(ByRef $Object) Json_ObjGetKeys(ByRef $Object) Json_ObjClear(ByRef $Object) These functions are just warps of "Scripting.Dictionary" COM object. You can use these functions if you are not already familiar with it. == Update 2013/05/19 == * Add Jsmn_Encode() option "$JSMN_UNESCAPED_ASCII". Now the default output of Json_Encode() is exactly the same as PHP's json_encode() function (for example, chr(1) will be encoded into u0001). $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) == Update 2015/01/08 == * Rename the library from jsmn.au3 to json.au3. All function names are changed, too. * Add Json_Put() and Json_Get() * Add Null support * Using BinaryCall.au3 to loading the machine code. == Update 2018/01/13== (Jos) * Add JsonDump() to list all Json Keys and their values to easily figure out what they are. == Update 2018/10/01== (Jos) * Fixed JsonDump() some fields and values were not showing as discussed here - tnx @TheXman . == Update 2018/10/01b== (Jos) * Added Json_ObjGetItems, Tidied source and fixed au3check warnings - tnx @TheXman . == Update 2018/10/28== (Jos) * Added declaration for $value to avoid au3check warning - tnx @DerPensionist == Update 2018/12/16== (Jos) * Added another declaration for $value to avoid au3check warning and updated the version at the top - tnx @maniootek == Update 2018/12/29== (Jos) * Changed Json_ObjGet() and Json_ObjExists() to allow for multilevel object in string. == Update 2019/01/17== (Jos) * Added support for DOT notation in JSON functions. == Update 2019/07/15== (Jos) * Added support for reading keys with a dot inside when using a dot as separator (updated) == Update 2021/11/18== (TheXman) * Update details in below post: == Update 2021/11/20== (TheXman) * Minor RegEx update, no change to the functionality or result._Json(2021.11.20).zip1 point
-
LOL!! Now ya tell me!! ROFL!! Good stuff!!1 point
-
Please delete
argumentum reacted to Melba23 for a topic
MattHigggs, So why not post it to perhaps help others with the same problem in the future? M231 point -
Child GUI's broken & won't align to parent
pixelsearch reacted to aa2zz6 for a topic
@pixelsearch This is perfect!! Thank you!1 point -
Child GUI's broken & won't align to parent
aa2zz6 reacted to pixelsearch for a topic
@aa2zz6 : I tried a different approach for the position of child GUI's in this simplified script. Hope it helps #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; List App Variables Global $hGUI_Child_Workforce, $hGUI_Child_Dashboard, $hGUI_Main = GUICreate("", 250, 300) ; Create app BTN [1] $btnWorkforce = IconButton("Workforce", 15, 25, 140, 40, 30, @ScriptDir & "\workforce.ico") ; Create app BTN [2] $btnDashboard = IconButton("Dashboard", 15, 80, 140, 40, 30, @ScriptDir & "\operations-dashboard.ico") ; Create Child GUI [1] _Create_Child_Workforce($hGUI_Main) ; Create Child GUI [2] _Create_Child_Dashboard($hGUI_Main) GUIRegisterMsg($WM_MOVE, "_Position_Child") GUISetState(@SW_SHOW, $hGUI_Main) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnWorkforce GUISetState(@SW_HIDE, $hGUI_Child_Dashboard) GUISetState(@SW_SHOW, $hGUI_Child_Workforce) Case $btnDashboard GUISetState(@SW_HIDE, $hGUI_Child_Workforce) GUISetState(@SW_SHOW, $hGUI_Child_Dashboard) EndSwitch WEnd ;====================================== Func IconButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $BIconSize, $BIDLL, $BIconNum = -1) GUICtrlCreateIcon($BIDLL, $BIconNum, $BIleft + 5, $BItop + (($BIheight - $BIconSize) / 2), $BIconSize, $BIconSize) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetState(-1, $GUI_DISABLE) $XS_btnx = GUICtrlCreateButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $WS_CLIPSIBLINGS) Return $XS_btnx EndFunc ;==>IconButton ;====================================== Func _Create_Child_Workforce($hGUI_Main) Local $lnCount = 600 Local $aGUI_Main_Pos = WinGetPos($hGUI_Main) $hGUI_Child_Workforce = GUICreate("Follower 1", 800, $lnCount, $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2], $aGUI_Main_Pos[1], _ BitOR($WS_POPUP, $WS_BORDER), -1, $hGUI_Main) GUISetBkColor(0xCCFFCC) GUISetFont(11, 400, Default, "Arial") Local $text = GUICtrlCreateLabel("Workforce", 10, 10, 380, ($lnCount * 20) - 20) EndFunc ;==>_Create_Child_Workforce ;====================================== Func _Create_Child_Dashboard($hGUI_Main) Local $lnCount = 600 Local $aGUI_Main_Pos = WinGetPos($hGUI_Main) $hGUI_Child_Dashboard = GUICreate("Follower 2", 800, $lnCount, $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2], $aGUI_Main_Pos[1], _ BitOR($WS_POPUP, $WS_BORDER), -1, $hGUI_Main) GUISetBkColor(0xCCFFCC) GUISetFont(11, 400, Default, "Arial") Local $text = GUICtrlCreateLabel("Dashboard", 10, 10, 380, ($lnCount * 20) - 20) EndFunc ;==>_Create_Child_Dashboard ;====================================== Func _Position_Child($hGUI_Main, $iMsg, $wParam, $lParam) Local $aGUI_Main_Pos = WinGetPos($hGUI_Main) WinMove($hGUI_Child_Workforce, "", $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2], $aGUI_Main_Pos[1]) WinMove($hGUI_Child_Dashboard, "", $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2], $aGUI_Main_Pos[1]) ; Return $GUI_RUNDEFMSG ; (?) EndFunc ;==>_Position_Child workforce.ico operations-dashboard.ico1 point -
I forgot to mention that _Excel_RangeCopyPaste() will do this too. #include <Excel.au3> example() Func example() Local $oExcel, $oSourceSheet, $oSourceRange, $oTargetRange $oExcel = _Excel_Open() _Excel_BookNew($oExcel) _Excel_BookNew($oExcel) With $oExcel ;Write A-Z across row 1 to Book1 For $iCol = 1 To 26 ;Cols A-Z .Workbooks("book1").Sheets("Sheet1").Cells(1, $iCol) = Chr(Asc("A") + ($iCol - 1)) Next ;Copy A1:E1 in Book1/Sheet1 to A1 in Book2/Sheet1 $oSourceSheet = .Workbooks("Book1").Sheets("Sheet1") $oSourceRange = $oSourceSheet.Range("A1:E1") $oTargetRange = .Workbooks("Book2").Sheets("Sheet1").Range("A1") _Excel_RangeCopyPaste($oSourceSheet, $oSourceRange, $oTargetRange) EndWith EndFunc1 point
-
Thank you for the reply. When I pressed F6, typed the following path, and pressed OK, I got an error. $(sys.PROGRAMFILES)\AutoIt3\AutoIt3.exe $(FULL_CURRENT_PATH) AutoIt Error Line 0 (File "C:\Documents"): Error: Error opening the file. So, I tried the path to have quotation marks and it worked. Thank you so much. $(sys.PROGRAMFILES)\AutoIt3\AutoIt3.exe "$(FULL_CURRENT_PATH)" However, when I do it from F5, nothing happens. I tried the following four lines for F5, $(sys.PROGRAMFILES)\AutoIt3\AutoIt3.exe $(FULL_CURRENT_PATH) $(sys.PROGRAMFILES)\AutoIt3\AutoIt3.exe "$(FULL_CURRENT_PATH)" C:\Program Files\AutoIt3\AutoIt3.exe $(FULL_CURRENT_PATH) C:\Program Files\AutoIt3\AutoIt3.exe "$(FULL_CURRENT_PATH)" Just for now, I'll go with the F6 solution, but if anybody knows what I should do with F5 please let me know. Edit: the following line worked for F5. Thanks. "C:\Program Files\AutoIt3\AutoIt3.exe" "$(FULL_CURRENT_PATH)"1 point