Leaderboard
Popular Content
Showing content with the highest reputation on 02/07/2013 in all areas
-
I've seen them But I wouldn't start with one of the most complex examples to explain to a user who just gets his feet wet on the subject.2 points
-
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
-
_GUICtrlComboBox_SelectString does not update the controls
Vitaliy4us reacted to PhoenixXL for a topic
ControlCommand Function "SelectString", 'string' Parameters Check the help file This would help you Regards Phoenix XL1 point -
Start with _ExcelBookOpen, _ExcelReadArray and _ExcelBookClose to read your data. Functions _IECreate or _IEAttach, _IEFormGetObjByName and _IEFormElementSetValue, _IEQuit will show how to insert the data. Details plus examples can be found in the help file.1 point
-
Form Builder beta
matwachich reacted to BuckMaster for a topic
I have explained this in previous posts, when creating controls, Left click is a click and drag operation to auto resize the control Right click is to create the control at a standardized size As for the spaces, its something I always do, i dont know why. The source script i provide is not intended to be executed, its main purpose is learning, I dont provide all of the resource files, and all of the non-standard includes can be easily found searching the forums.1 point -
Some mathematical calculation can do better job without the need of the Variables Check the example for understanding #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $guiWidth = 500 Global $guiHeght = 500 GUICreate("", $guiWidth, $guiHeght) GUICtrlCreateLabel("", $guiWidth * 28 / 100, 8, $guiWidth, 17) GUICtrlCreateTab(2, 25, $guiWidth - 4, $guiHeght - 27) GUICtrlCreateTabItem("Buffs") ESBTab() GUICtrlCreateTabItem("") GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate") While 1 Sleep(100) WEnd Func ESBTab() Local $left = 30, $bTop Local $top = 60, $bLeft Local $ESBLeft = $left + 15 Local $ESBLeft2 = $ESBLeft + 110 Local $ESBTop = $top + 25 GUICtrlCreateGroup("Buffs :", $left, $ESBTop, $guiWidth - 60, 250) For $i = 0 To 3 $bTop = $ESBTop $bLeft = $left + 30 Switch $i Case 0 $bTop += 35 Case 1 $bTop += 35 $bLeft += 225 Case 2 $bTop += 120 Case 3 $bTop += 120 $bLeft += 225 EndSwitch GUICtrlCreateCheckbox("Buff " & $i + 1, $bLeft, $bTop) GUICtrlSetOnEvent(-1, "_activebuff") GUICtrlCreateLabel("Key : ", $bLeft + 10, $bTop + 25, 50, 15) GUICtrlCreateInput("", $bLeft + 80, $bTop + 25, 50, 15) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel("Delay (in ms) : ", $bLeft + 10, $bTop + 50, 65, 15) GUICtrlCreateInput("", $bLeft + 80, $bTop + 50, 50, 15, 0x2000) GUICtrlSetState(-1, $GUI_DISABLE) Next GUICtrlCreateGroup("", -99, -99, 1, 1) EndFunc ;==>ESBTab Func _activebuff() If GUICtrlRead(@GUI_CtrlId) == $GUI_CHECKED Then GUICtrlSetState(@GUI_CtrlId + 2, $GUI_ENABLE) GUICtrlSetState(@GUI_CtrlId + 4, $GUI_ENABLE) Else GUICtrlSetState(@GUI_CtrlId + 2, $GUI_DISABLE) GUICtrlSetState(@GUI_CtrlId + 4, $GUI_DISABLE) EndIf EndFunc ;==>_activebuff Func _Terminate() Exit EndFunc ;==>_TerminateThumbs up if it helped1 point
-
Excel to Webform
ShakeelAhmad reacted to jdelaney for a topic
Use the _Excel and _IE functions...they are much more relaible (don't have to worry about the tab not being picked up durring the run), and will take down that 30 seconds enter time to seconds (if even)1 point -
How to send .txt file to the email address
minimen456 reacted to water for a topic
Sure: #include <OutlookEx.au3> $oOL = _OL_Open() If @error <> 0 Then Exit MsgBox(16, "Test", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended) $sTo = "recipients mail address" $sSubject = "Subject of the mail" $sBody = "Body text of the mail" $sAttachments = "C:\temp\results\abcd.text" _OL_Wrapper_SendMail($oOL, $sTo, "", "", $sSubject, $sBody, $sAttachments) If @error <> 0 Then MsgBox(16, "Test", "Error sending mail. @error = " & @error & ", @extended: " & @extended) _OL_Close($oOL)1 point -
_GUICtrlListView_AddArray()
DiscGolferPro reacted to KaFu for a topic
, that's why it took 7 seconds... Threw together a dynamic example (dirty ) from the help-file, how to dynamically determine the columns and records. Could definitely do some more error checking, but it works under the given circumstances and might be a good start point (only appoint as much memory to the array as needed). #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include<WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Global $iTimer, $hListView, $aItems, $itemcount Global $hQuery, $aRow Global $aNames[1], $aRow[1], $aItems[1][1] ; Create GUI GUICreate("ListView Add Array", 400, 300) $hListView = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($WS_EX_STATICEDGE, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) $hListView = GUICtrlGetHandle($hListView) _GUICtrlListView_SetUnicodeFormat($hListView, False) _SQLite_Startup() _SQLite_Open(); open :memory: Database _SQLite_Exec(-1, "CREATE TABLE aTest (col_a,col_b,col_c);") For $i = 1 To 5000 _SQLite_Exec(-1, "INSERT INTO aTest(col_a,col_b,col_c) VALUES (" & $i & "," & $i+1 & ","& $i+2 &");") Next GUISetState() _SQLite_Query(-1, "SELECT count(*) FROM aTest;", $hQuery) If _SQLite_FetchData($hQuery, $aRow) <> $SQLITE_OK Then MsgBox(270400, '', "No records were found in the result set...") ReDim $aRow[1] $aRow[0] = 0 EndIf _SQLite_QueryFinalize($hQuery) If $aRow[0] > 0 Then _SQLite_Query(-1, "SELECT * FROM aTest LIMIT 1;", $hQuery) _SQLite_FetchNames($hQuery, $aNames); Read out Column Names _SQLite_QueryFinalize($hQuery) For $i = 1 To UBound($aNames) _GUICtrlListView_AddColumn($hListView, $aNames[$i-1], 100) Next $itemcount = $aRow[0] ReDim $aItems[$itemcount][UBound($aNames)] $i = 0 _SQLite_Query(-1, "SELECT * FROM aTest;", $hQuery) While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK For $y = 0 To UBound($aNames) - 1 $aItems[$i][$y] = $aRow[$y] Next $i += 1 WEnd _SQLite_QueryFinalize($hQuery) _GUICtrlListView_SetItemCount($hListView, UBound($aItems) - 1) $iTimer = TimerInit() _GUICtrlListView_AddArray($hListView, $aItems) MsgBox(4160, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds") EndIf Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() _SQLite_Close() _SQLite_Shutdown()1 point