Leaderboard
Popular Content
Showing content with the highest reputation on 03/01/2016 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
-
Automate all windows and browser applications with one UDF function library. Based on the microsoft automation API this library high level supports Recognition of conttrols from EDGE, Chrome, FF, Opera, Safari and Windows native apps Small testing framework to split object repository from coding away Introduction Quickstart - Getting started quickly Simple scripts With this module you can automate all applications/programs that support ui automation and/or accesibility api from microsoft you can recognize more controls than AutoIT can recognize "out of the box" you can use concepts from other testing frameworks like http://download.freedesktop.org/ldtp/doc/ldtp-tutorial.pdf http://safsdev.sourceforge.net/Default.htm coded ui testing from microsoft Some of those controls / applications are chrome browser (partly mainwindow has to be done with MSAA for navigating) chrome://accessibility in the adress bar of chrome or start with "--force-renderer-accessibility" silverlight controls Ribbon control controlbars of Excel/Word IE and FF browsers Windows Media Player Windows clock AFX .. controls (partly) .... Based on the initial AIO Object I now have made the interface file to work with objCreateInterface function which is in the latest beta's automate clicking and querying basic information It gives you a lot of basic information to be able to automate clicking, querying basic information where it goes further in certain situations than AutoIt is identifying Starting threads for background on the ui automation api of microsoft (not for starters) http://en.wikipedia.org/wiki/Microsoft_UI_Automation http://msdn.microsoft.com/en-us/library/ms747327.aspx Previous threads in general help/support Interface AutoItObject IUIAutomation ObjCreateInterface and struct tagPoint in method ElementFromPoint Be aware that API is not allways installed under XP/Vista see http://support.microsoft.com/kb/971513 Within Windows 7 and Windows 8 it should be preinstalled by default. Be aware on 32 and 64 bits way of running your script #AutoIt3Wrapper_UseX64=Y or N Basic example of usage / showing and retrieving the default information, will post multiple examples later Hover your mouse to an area of interest and press ctrl+w and information will be shown in the edit box of the form Simple spy demo (see simplespy.au3 or use latest ZIP attachment for latest version) Main features Recognize windows and html controls for the major browsers Logical and physical description for controls (UI mapping, Application map) Simple repository logic to abstract logical and physical descriptions Store Runtime Type Information in RTI. variables Rubberbanding/highlighting of objects Simple spy to help in making / identifying the physical description Support of regular expression(s) in identifying objects recognize objects on multiple properties supported properties: name ,title, automationid, classname, class, iaccessiblevalue, iaccessiblechildId, controltype, processid, acceleratorkey The actions provided so far "leftclick", "left", "click", "leftdoubleclick", "leftdouble", "doubleclick", _ "rightclick", "right", "rightdoubleclick", "rightdouble", _ "middleclick", "middle", "middledoubleclick", "middledouble", "mousemove", "movemouse" "setvalue","settextvalue" "setvalue using keys" "setValue using clipboard" "getvalue" "sendkeys", "enterstring", "type", "typetext" "invoke" "focus", "setfocus", "activate" "close" "move","setposition" "resize" "minimize", "maximize", "normal", "close", "exist", "exists" "searchcontext", "context" "highlight" "getobject","object" "attach" "capture","screenshot", "takescreenshot" "dump", "dumpthemall" "propertyvalue", "property" match on multiple properties like: name:=((Zoeken.*)|(Find.*)); ControlType:=Button; acceleratorkey:=Ctrl+F Support for 117 different properties see $UIA_propertiesSupportedArray in uiawrappers like for example title, regexptitle, class, regexpclass, iaccessiblevalue, iaccessiblechildid, name, accesskey, automationid, classname IAccessible, IAccessible2, ISimpleDom interfaces debuglogging to a file log.txt (no output in scitewindow) Examples Example 1 Iterating thru the different ways of representing the objects in the tree (#comment-1105548) Example 2 Finding the taskbar and clicking on the start menu button (#comment-1105680) Example 3 Clicking a litlle more and in the end displaying all items from the clock (thats not directly possible with AU3Info) (#comment-1108849) Example 4 that demonstrates the calculator Example 5 Automating chrome Example 6 Demonstrates all stuff within chrome to navigate html pages, find hyperlink, click hyperlink, find picture, click picture, enter data in inputbox Example 7 The chrome example modified to a firefox example Example 8 The other major browser Internet Explorer automated (made on Example 6 and 7) Example 9 Windows media player Example 10 Automating mach 3 (AFX windows and other hard to get recognized by AutoIT) Lot of links are broken due to forum upgrade just search for the text like "Example 11 Demonstrate Word, Notepad and Calculator actions" Example 11 Demonstrate Word, Notepad and Calculator actions ... Example 13 Details 1 about the right pane of the windows explorer Example 14 Details 2 about the right pane of the windows explorer Example 15 Details 3 about the right pane of the windows explorer Example 16 Details 4 about the right pane of the windows explorer Example 17 Details 5 about the right pane of the windows explorer WITH CACHING Example 18 Details 6 about the right pane of the windows explorer WITH VIRTUAL ITEMS Example 19 Eventhandling examples Example 20 Eventhandling examples Example 21a Eventhandling examples Internet Explorer Example 21b Eventhandling examples Internet Explorer Example 22 Eventhandling examples Follow focus Example 23 Eventhandling examples structure changed Example 24 Eventhandling examples IUIAutomationEventHandler Example 25 SAFEARRAYS Example 26 IACCESSIBLE / MSAA Example 27 IACCESSIBLE2 / MSAA Example 28 IACCESSIBLE / MSAA events Example 29 IACCESSIBLE2 events Example 30 ISimpleDOM Example 31 Notepad window move, maximize, minimize Example 32 Three browsers doing the same stuff with small differences in scripting only .. TODO Build recorder Enhance the spy with a nicer UI UI for the repository (now in the script with dot notation) Enhance mapping / identifying on multiple properties instead of 1 combined with index If speed becomes an issue use the caching logic of the MS UIA framework Add the other patterns later Generalize the concept of System Under Test of starting the SUT (for testing framework purposes) Remote running of scripts Fix issue on finding within dynamic context ... edit august 18th 2013 initial post Only zip files are needed to download , just unzip in 1 directory edit july 2016 Made V0_63 and examples works with AutoIt v3.3.14 Windows 10 tested Simple spy gives some basic code as a present Chrome latest versions seems to be having issues with IUIAutomation on tabs/buttons of mainwindow use MSAA for accessing tabsheets / buttons more cleanup to be in UDF style More comments in the source see changelog.txt for previous changes edit september 2017 All examples fixed for the IE, Firefox and Chrome browser Some small but essential fixes in UIAWrappers edit april 2018 Enhanced logic on fallback / dynamic search, still not perfect, to slow Retested with latest Chrome, FF, Edge and IE11 and some extensions to show how to get text from the webpage (examples 5,6,7) Some small bugfixes Some comments as given in forum incorporated edit may 2019 Speed enhancements on especially fallback searching UIA.CFG works now in a better way to turn on/off debug, highlighting, debug2file More stable and consistent behavior Internal cleanup and refactoring of bigger functions Checked with W10 (not tested on W7) Added some W10 properties Run with 3.3.14.5 on W10 UIA_V0_51.zip EXAMPLES_V0_5.zip UIA_V0_63.zip EXAMPLES_V0_63.zip UIA_V0_64.zip EXAMPLES_V0_64.zip EXAMPLES_V0_66.zip UIA_V0_66.zip EXAMPLES_V0_70.zip UIA_V0_70.zip1 point
-
BIOS Informations UDF
mLipok reacted to MasterKnack for a topic
This UDF gets basic information about BIOS. I'm author of this udf, and this is my first udf. Example: #include "BIOS.au3" Example() Func Example() MsgBox(0, "", _ @CRLF & "BIOS Release Date...........| "& _BIOS_Release_Date() & _ @CRLF & "BIOS Vendor.....................| "&_BIOS_Vendor() & _ @CRLF & "BIOS Version....................| "& _BIOS_Version() & _ @CRLF & "System BIOS Version.......| "& _BIOS_SysBIOSVer() & _ @CRLF & "System Family..................| "& _BIOS_SysFamily() & _ @CRLF & "System Manufacturer......| "& _BIOS_SysManufacturer() & _ @CRLF & "System Product Name....| "& _BIOS_SysProdcName() & _ @CRLF & "System Version.................| "&_BIOS_SysVer()& _ @CRLF & "System SKU........................| "&_BIOS_SKU()) EndFunc BIOS.au31 point -
1 point
-
Projects need MYSQL , I should take any UDFs?
Rechard_Long reacted to mLipok for a topic
There is no need to you such a big font size. There is no need to quote post each time when you want to post.1 point -
Projects need MYSQL , I should take any UDFs?
Rechard_Long reacted to mLipok for a topic
Try new version: Especially:1 point -
Projects need MYSQL , I should take any UDFs?
Rechard_Long reacted to mLipok for a topic
Re read my edited previous post.1 point -
Projects need MYSQL , I should take any UDFs?
Rechard_Long reacted to mLipok for a topic
First you should install MySQL driver for windows. https://dev.mysql.com/downloads/connector/odbc/ edit: After install process put here your new list again.1 point -
Projects need MYSQL , I should take any UDFs?
Rechard_Long reacted to mLipok for a topic
My fault - I recently modified the function. I fixed this example on Wiki. Try Again.1 point -
Try these lines and it should work: Local $iIndex2 = _GUICtrlListView_GetSelectedIndices($idListview) $GDIpBmpResizedx = _GDIPlus_ImageResize($hImage_new2, 64, 64) ;GDI+ imagez $GDIbmpx = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResizedx) ;GDI image! _GUIImageList_Replace($hImage, $iIndex2, $GDIbmpx)1 point
-
how to make this script run faster??
langthang084 reacted to UEZ for a topic
Using maps seems to be very fast: #AutoIt3Wrapper_Version=b #include <array.au3> $TotalWord = 100000 Local $SourceText[$TotalWord] = [''] $fTimer = TimerInit() For $a = 0 To $TotalWord - 1 $SourceText[$a] = 'ABC' & Random(1, 9, 1) Next ConsoleWrite("Array created in " & TimerDiff($fTimer) & " ms" & @CRLF) $fTimer = TimerInit() $Export = _Classified($SourceText) ConsoleWrite(TimerDiff($fTimer) & @CRLF) _ArraySort($Export) _ArrayDisplay($Export, 'Export') $fTimer = TimerInit() $Export = _Classified3($SourceText) ConsoleWrite(TimerDiff($fTimer) & @CRLF) _ArraySort($Export) _ArrayDisplay($Export, 'Export') $fTimer = TimerInit() $Export2 = _Classified2_UEZ($SourceText) ConsoleWrite(TimerDiff($fTimer) & @CRLF) Local $aResult[UBound($Export2)][2] $y = 0 For $key In $Export2.keys() $aResult[$y][0] = $key $aResult[$y][1] = $Export2[$key] $y += 1 Next _ArraySort($aResult) _ArrayDisplay($aResult) Func _Classified2_UEZ($SourceArray) Local $aMaps[], $i For $i = 0 To UBound($SourceArray) - 1 If $aMaps.Exists($SourceArray[$i]) Then $aMaps[$SourceArray[$i]] += 1 Else $aMaps[$SourceArray[$i]] = 1 EndIf Next Return $aMaps EndFunc ;==>_Classified2_UEZ Func _Classified3($SourceArray) ;~ ProgressOn('Classified2', 'Start Sort') _ArraySort($SourceArray, 0, 0, 0, 0, 1) Local $ExportArray[UBound($SourceArray)][2] Local $LastWord Local $WordOccCount = 0 Local $WordCount = 0 Local $EndLoop = UBound($SourceArray) - 1 ;~ ProgressSet(0, '0%', 'Start counting') For $a = 1 To UBound($SourceArray) - 1 ;~ If mod($a,int($EndLoop/100)) = 0 Then ;~ ProgressSet(Int(($a / $EndLoop) * 100), Int(($a / $EndLoop) * 100) & '%') ;~ EndIf If $a = 1 Then $LastWord = $SourceArray[$a] $WordCount = 1 $WordOccCount = 1 ContinueLoop EndIf If $LastWord = $SourceArray[$a] Then $WordOccCount += 1 Else $ExportArray[$WordCount][0] = $LastWord $ExportArray[$WordCount][1] = $WordOccCount $LastWord = $SourceArray[$a] $WordCount += 1 $WordOccCount = 1 EndIf Next $ExportArray[$WordCount][0] = $LastWord $ExportArray[$WordCount][1] = $WordOccCount ;~ ProgressOff() _ArrayDelete($ExportArray, 0) ReDim $ExportArray[$WordCount][2] ;_ArrayDisplay($ExportArray, 'After Distribute') Return $ExportArray EndFunc ;==>_Classified3 Func _Classified($SourceArray) ;~ ProgressOn('Classified', '') Local $ExportArray[][] = [['', '']] $EndLoop = UBound($SourceArray) - 1 For $a = 1 To UBound($SourceArray) - 1 ;~ ProgressSet( int(($a/$EndLoop)*100), int(($a/$EndLoop)*100) & '%' ) $Line = _ArraySearch($ExportArray, $SourceArray[$a], 0, 0, 0, 1) If @error Then _ArrayAdd($ExportArray, '') $ExportArray[UBound($ExportArray) - 1][0] = $SourceArray[$a] $ExportArray[UBound($ExportArray) - 1][1] = 1 Else $ExportArray[$Line][1] += 1 EndIf Next ;~ ProgressOff() _ArrayDelete($ExportArray, 0) ;_ArrayDisplay($ExportArray, 'After Distribute') Return $ExportArray EndFunc ;==>_Classified To test this function you need the latest beta!1 point -
You should read this: Remote Desktop ActiveX control interfaces https://msdn.microsoft.com/en-us/library/windows/desktop/aa383022(v=vs.85).aspx ITSRemoteProgram interface https://msdn.microsoft.com/en-us/library/windows/desktop/aa382947(v=vs.85).aspx ITSRemoteProgram::ServerStartProgram method https://msdn.microsoft.com/en-us/library/windows/desktop/aa382952(v=vs.85).aspx ITSRemoteProgram2 interface https://msdn.microsoft.com/en-us/library/windows/desktop/ff808366(v=vs.85).aspx EDIT: And here you can find example: https://social.technet.microsoft.com/Forums/windowsserver/en-US/1b3f1f70-9eea-45d8-a6c4-5c5a71e6fa1a/launch-ts-remote-app-from-terminal-services-api?forum=winserverTS btw. Please read: How to post code on the forum1 point
-
Win 7 64 bit Enterprise. Had to use Global $regkey = "HKLM\Hardware\Description\System\BIOS" to make it work.1 point
-
How about this (no UDF, just an example Script generated by Scriptomatic): ; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "." $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $strBiosCharacteristics = $objItem.BiosCharacteristics(0) $Output = $Output & "BiosCharacteristics: " & $strBiosCharacteristics & @CRLF $strBIOSVersion = $objItem.BIOSVersion(0) $Output = $Output & "BIOSVersion: " & $strBIOSVersion & @CRLF $Output = $Output & "BuildNumber: " & $objItem.BuildNumber & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "CodeSet: " & $objItem.CodeSet & @CRLF $Output = $Output & "CurrentLanguage: " & $objItem.CurrentLanguage & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "IdentificationCode: " & $objItem.IdentificationCode & @CRLF $Output = $Output & "InstallableLanguages: " & $objItem.InstallableLanguages & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "LanguageEdition: " & $objItem.LanguageEdition & @CRLF $strListOfLanguages = $objItem.ListOfLanguages(0) $Output = $Output & "ListOfLanguages: " & $strListOfLanguages & @CRLF $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "OtherTargetOS: " & $objItem.OtherTargetOS & @CRLF $Output = $Output & "PrimaryBIOS: " & $objItem.PrimaryBIOS & @CRLF $Output = $Output & "ReleaseDate: " & WMIDateStringToDate($objItem.ReleaseDate) & @CRLF $Output = $Output & "SerialNumber: " & $objItem.SerialNumber & @CRLF $Output = $Output & "SMBIOSBIOSVersion: " & $objItem.SMBIOSBIOSVersion & @CRLF $Output = $Output & "SMBIOSMajorVersion: " & $objItem.SMBIOSMajorVersion & @CRLF $Output = $Output & "SMBIOSMinorVersion: " & $objItem.SMBIOSMinorVersion & @CRLF $Output = $Output & "SMBIOSPresent: " & $objItem.SMBIOSPresent & @CRLF $Output = $Output & "SoftwareElementID: " & $objItem.SoftwareElementID & @CRLF $Output = $Output & "SoftwareElementState: " & $objItem.SoftwareElementState & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "TargetOperatingSystem: " & $objItem.TargetOperatingSystem & @CRLF $Output = $Output & "Version: " & $objItem.Version & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_BIOS" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc1 point
-
1 point
-
Isn't it possible to get "real" data from the BIOS like Windows does when it fills the registry?1 point
-
win10 x64 enterprise nothing. EDIT: {03000200-0400-0500-0006-000700080009} Works1 point
-
Witam cię Patryku na Forum AutoIt I welcome you Patryk on AutoIt Forum. I change your example a little bit: #include "BIOS.au3" Example() Func Example() ConsoleWrite( _ @CRLF & "BIOS Release Date.......| " & _BIOS_Release_Date() & _ @CRLF & "BIOS Vendor.............| " & _BIOS_Vendor() & _ @CRLF & "BIOS Version............| " & _BIOS_Version() & _ @CRLF & "System BIOS Version.....| " & _BIOS_SysBIOSVer() & _ @CRLF & "System Family...........| " & _BIOS_SysFamily() & _ @CRLF & "System Manufacturer.....| " & _BIOS_SysManufacturer() & _ @CRLF & "System Product Name.....| " & _BIOS_SysProdcName() & _ @CRLF & "System Version..........| " & _BIOS_SysVer() & _ @CRLF & "System SKU..............| " & _BIOS_SKU() & _ "") EndFunc ;==>Example Unfortunately, the result is not correct: I'm using Windows 10. Which version you are using ? Can some body share results from different system ? mLipok EDIT: Please also read: Best coding practices especially about https://www.autoitscript.com/wiki/Best_coding_practices#Names_of_Variables1 point
-
JoachimR. Use Au3Stripper with the /MergeOnly flag to get the file as passed to Aut2Exe - then the line numbers will match. See SciTE help for more full details. But better still - debug the script and prevent the error by adding some form of errorchecking code. M231 point
-
This is a really crude way of reading a simple (I mean simple) INI file and not having to read and write all the time using the INI functions. I know something like this already exists by AZJIO, but I wanted to target the newbie market. It uses no global variables (the enums are only there so I don't have to worry about what 0,1,2 actually means) and only 2 static variables, filepath and dictionary. Enjoy! #include <FileConstants.au3> #include <StringConstants.au3> Global Const $VARGETTYPE_BINARY = 'Binary', _ $VARGETTYPE_BOOL = 'Bool', _ $VARGETTYPE_DOUBLE = 'Double', _ $VARGETTYPE_INT32 = 'Int32', $VARGETTYPE_INT64 = 'Int64', _ $VARGETTYPE_PTR = 'Ptr', _ $VARGETTYPE_STRING = 'String' Global Const $SETTINGS_DATATYPE_BINARY = '(binary)', _ $SETTINGS_DATATYPE_BOOL = '(bool)', _ $SETTINGS_DATATYPE_DOUBLE = '(double)', _ $SETTINGS_DATATYPE_INT = '(int)', _ $SETTINGS_DATATYPE_PTR = '(ptr)', _ $SETTINGS_DATATYPE_STRING = '(string)' Global Const $SETTINGS_GUID = 'D6FFD9DF-F1B7-4C07-89C3-F8B597EEC1CF' Global Enum $SETTINGS_ASSOC, $SETTINGS_DUMP, $SETTINGS_FILEPATH, $SETTINGS_ID, $SETTINGS_MAX, $SETTINGS_GET, $SETTINGS_SET, $SETTINGS_SHUTDOWN, $SETTINGS_STARTUP Global Enum $SETTINGS_KEY, $SETTINGS_DATATYPE, $SETTINGS_VALUE Example() ; Useful if you only have a single settings file for the application. Func Example() Local $hSettings = _Settings(@ScriptDir & '\Settings.ini') ; Start the settings by passing the filepath that returns a settings object. ConsoleWrite(_Settings_Get($hSettings, 'Language', 'None') & @CRLF) ; Get the language key value of the settings object. ConsoleWrite(_Settings_Set($hSettings, 'Language', 'English') & @CRLF) ; Set the language key value to English using the settings object. ConsoleWrite(_Settings_Set($hSettings, 'Number', 100) & @CRLF) ; Set the int key value to 100 using the settings object. ConsoleWrite(_Settings_Get($hSettings, 'Language', 'None') & @CRLF) ; Get the language key value of the settings object. ConsoleWrite(_Settings_Get($hSettings, 'Int', 'None') & @CRLF) ; Get the int key value of the settings object. _Settings_Dump($hSettings) ; Dump the settings object to disk. ConsoleWrite(_Settings_FilePath($hSettings) & @CRLF) ; Get the filepath of the settings object. EndFunc ;==>Example ; Useful if you only Func Example_Static() If _Settings_Static(@ScriptDir & '\Settings_Static.ini') Then; Start the settings by passing the filepath. This returns either true or false. ConsoleWrite(_Settings_Static_Get('Language', 'None') & @CRLF) ; Get the language key value. ConsoleWrite(_Settings_Static_Set('Language', 'English') & @CRLF) ; Set the language key value to English. ConsoleWrite(_Settings_Static_Set('Number', 100) & @CRLF) ; Set the int key value to 100. ConsoleWrite(_Settings_Static_Get('Language', 'None') & @CRLF) ; Get the language key value. ConsoleWrite(_Settings_Static_Get('Int', 'None') & @CRLF) ; Get the int key value _Settings_Static_Dump() ; Dump the settings to disk. ConsoleWrite(_Settings_Static_FilePath() & @CRLF) ; Get the filepath of the settings. EndIf EndFunc ;==>Example_Static Func _Settings($sFilePath) Local $aSettings[$SETTINGS_MAX] If _AssociativeArray_Startup($aSettings[$SETTINGS_ASSOC], False) Then Local $aSRE = StringRegExp(FileRead($sFilePath), '(?:^|\R)([^=]+)=(\(\w+\))([^\r\n]*)', $STR_REGEXPARRAYGLOBALMATCH), _ $vValue = 0 For $i = 0 To UBound($aSRE) - 1 Step 3 $vValue = $aSRE[$i + $SETTINGS_VALUE] Switch $aSRE[$i + $SETTINGS_DATATYPE] Case $SETTINGS_DATATYPE_BINARY $vValue = Binary($vValue) Case $SETTINGS_DATATYPE_BOOL $vValue = (($vValue == 'True') ? True : False) Case $SETTINGS_DATATYPE_DOUBLE $vValue = Number($vValue) Case $SETTINGS_DATATYPE_INT $vValue = Int($vValue) Case $SETTINGS_DATATYPE_PTR $vValue = Ptr($vValue) Case Else $vValue = String($vValue) EndSwitch $aSettings[$SETTINGS_ASSOC].Item($aSRE[$i]) = $vValue Next $aSettings[$SETTINGS_FILEPATH] = $sFilePath $aSettings[$SETTINGS_ID] = $SETTINGS_GUID ; Set the GUID if the associative array was created successfully. Else $aSettings = Null ; Set to Null if an error occurred. EndIf Return $aSettings EndFunc ;==>_Settings Func _Settings_Dump(ByRef $aSettings) Local $bReturn = False If __Settings_IsAPI($aSettings) And $aSettings[$SETTINGS_DUMP] Then Local $aItems = $aSettings[$SETTINGS_ASSOC].Items(), $aKeys = $aSettings[$SETTINGS_ASSOC].Keys(), _ $iItemsUBound = UBound($aItems) If $iItemsUBound = UBound($aKeys) Then $bReturn = True Local $sData = '' For $i = 0 To UBound($aItems) - 1 Switch VarGetType($aItems[$i]) Case $VARGETTYPE_BINARY $aItems[$i] = $SETTINGS_DATATYPE_BINARY & $aItems[$i] Case $VARGETTYPE_BOOL $aItems[$i] = $SETTINGS_DATATYPE_BOOL & $aItems[$i] Case $VARGETTYPE_DOUBLE $aItems[$i] = $SETTINGS_DATATYPE_DOUBLE & $aItems[$i] Case $VARGETTYPE_INT32, $VARGETTYPE_INT64 $aItems[$i] = $SETTINGS_DATATYPE_INT & $aItems[$i] Case $VARGETTYPE_PTR $aItems[$i] = $SETTINGS_DATATYPE_PTR & $aItems[$i] Case Else $aItems[$i] = $SETTINGS_DATATYPE_STRING & $aItems[$i] EndSwitch $sData &= $aKeys[$i] & '=' & $aItems[$i] & @CRLF Next _SetFile($sData, $aSettings[$SETTINGS_FILEPATH], True) EndIf EndIf Return $bReturn EndFunc ;==>_Settings_Dump Func _Settings_FilePath(ByRef $aSettings) Return __Settings_IsAPI($aSettings) ? $aSettings[$SETTINGS_FILEPATH] : Null EndFunc ;==>_Settings_FilePath Func _Settings_Get(ByRef $aSettings, $sKey, $sDefault) If __Settings_IsAPI($aSettings) Then If $aSettings[$SETTINGS_ASSOC].Exists($sKey) Then $sDefault = $aSettings[$SETTINGS_ASSOC].Item($sKey) EndIf EndIf Return $sDefault EndFunc ;==>_Settings_Get Func _Settings_Set(ByRef $aSettings, $sKey, $sValue) Local $bReturn = False If __Settings_IsAPI($aSettings) Then $bReturn = True $aSettings[$SETTINGS_ASSOC].Item($sKey) = $sValue $aSettings[$SETTINGS_DUMP] = True EndIf Return $bReturn EndFunc ;==>_Settings_Set Func _Settings_Static($sFilePath) _Settings_Static_Dump() ; Dump the previous contents to disk. Return __Settings_Static($sFilePath, Null, $SETTINGS_STARTUP) EndFunc ;==>_Settings_Static Func _Settings_Static_Dump() Return __Settings_Static(Null, Null, $SETTINGS_DUMP) EndFunc ;==>_Settings_Static_Dump Func _Settings_Static_FilePath() Return __Settings_Static(Null, Null, $SETTINGS_FILEPATH) EndFunc ;==>_Settings_Static_FilePath Func _Settings_Static_Get($sKey, $sDefault) Return __Settings_Static($sKey, $sDefault, $SETTINGS_GET) EndFunc ;==>_Settings_Static_Get Func _Settings_Static_Set($sKey, $sValue) Return __Settings_Static($sKey, $sValue, $SETTINGS_SET) EndFunc ;==>_Settings_Static_Set Func _Settings_Static_Shutdown() _Settings_Static_Dump() ; Dump the previous contents to disk. Return __Settings_Static(Null, Null, $SETTINGS_SHUTDOWN) EndFunc ;==>_Settings_Static_Shutdown Func __Settings_Static($sKey, $sValue, $iAction) Local Static $hSettings = Null Local $vReturn = False Switch $iAction Case $SETTINGS_DUMP $vReturn = _Settings_Dump($hSettings) Case $SETTINGS_FILEPATH $vReturn = _Settings_FilePath($hSettings) Case $SETTINGS_GET ; Getter $vReturn = _Settings_Get($hSettings, $sKey, $sValue) Case $SETTINGS_SET ; Setter $vReturn = _Settings_Set($hSettings, $sKey, $sValue) Case $SETTINGS_SHUTDOWN $vReturn = True $hSettings = Null Case $SETTINGS_STARTUP $vReturn = True $hSettings = _Settings($sKey) EndSwitch Return $vReturn EndFunc ;==>__Settings_Static Func __Settings_IsAPI(ByRef $aSettings) Return UBound($aSettings) = $SETTINGS_MAX And $aSettings[$SETTINGS_ID] = $SETTINGS_GUID EndFunc ;==>__Settings_IsAPI Func _AssociativeArray_Startup(ByRef $aArray, $bIsCaseSensitive = False) ; Idea from MilesAhead. Local $bReturn = False $aArray = ObjCreate('Scripting.Dictionary') If IsObj($aArray) Then $aArray.CompareMode = ($bIsCaseSensitive ? 0 : 1) $bReturn = True EndIf Return $bReturn EndFunc ;==>_AssociativeArray_Startup Func _SetFile(ByRef $sString, $sFilePath, $bOverwrite = False, $iMode = Default) Local $hFileOpen = FileOpen($sFilePath, ($bOverwrite ? $FO_OVERWRITE : $FO_APPEND) + (IsDefault($iMode) ? 0 : $iMode)), _ $iError = 2 If $hFileOpen > -1 Then $iError = (FileWrite($hFileOpen, $sString) ? 0 : 1) FileClose($hFileOpen) EndIf Return SetError($iError, 0, $hFileOpen > -1) EndFunc ;==>_SetFile Func IsDefault($vDefault) Return $vDefault = Default EndFunc ;==>IsDefault1 point
-
Menu Bar Buttons Yesterday I stumbled upon an idea. I needed to add some buttons to my GUI, but didn't have enough room. There was plenty of room left on the menu bar, so that's where I decided put them. The method works fine on my machine (surprisingly perhaps). Please report if you experience any issues running the script, or if you know of a better way to do this. Thanks. ; #include <GuiconstantsEx.au3> #include <StaticConstants.au3> _MenuButtons() Func _MenuButtons() Local $hGUI = GUICreate("Menu Button Example", 270, 100) GUICtrlCreateMenu(" ") ; A menu has to be created first (this seems logical). GUICtrlSetState(-1, $GUI_DISABLE) ; The above menu is treated as a spacer. Local $hToStart = GUICtrlCreateMenuItem(" << ", -1) ; Menu items are now placed on the menu bar. Local $hStepBack = GUICtrlCreateMenuItem(" < ", -1) Local $hPlay = GUICtrlCreateMenuItem(" P ", -1) Local $hStepForward = GUICtrlCreateMenuItem(" > ", -1) Local $hToEnd = GUICtrlCreateMenuItem(" >> ", -1) Local $hLabel = GUICtrlCreateLabel("", 10, 25, 250, 20, $SS_CENTER) GUISetState(@SW_SHOW) Local $msg While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $hToStart GUICtrlSetData($hLabel, "Back to Start") Case $hStepBack GUICtrlSetData($hLabel, "Step Back") Case $hPlay GUICtrlSetData($hLabel, "Play / Pause") Case $hStepForward GUICtrlSetData($hLabel, "Step Forward") Case $hToEnd GUICtrlSetData($hLabel, "Forward to End") EndSwitch WEnd EndFunc ; The help file states that when setting menuID to -1 with GUICtrlCreateMenuItem(), '-1 refers to the first level menu'. For me, it's difficult to interpret what this means. The controls just appear on the menu bar, which I never (quite) thought of as being a menu: since it has no specific handle (that I know of) and is not clickable by default. Also consider that if you remove the menu created in the example above, the code will no longer work as expected. I am at a loss to explain this. Testers needed!1 point
-
A Non-Strict JSON UDF (JSMN)
Taz77 reacted to level20peon for a topic
Hello, thanks for this UDF, it has been really helpful so far. However, I got one JSON string that seems impossible to decode with this UDF (I validated it with a JSON validator, so does not seem to be invalid): I doesn't work in this form: #Include <JSMN.au3> $JSON='{"a":{"742597609":{"v":673,"p":4.91,"lb":"test1","av":58,"sl":11.6},"534165346":{"v":777,"p":5.66,"lb":"test2","av":58,"sl":13.3}},"b":16092018}' Local $objJson = Jsmn_Decode($JSON) If Jsmn_IsObject($objJson) Then Local $auctions = Jsmn_ObjGet($objJson, "a") For $i = 0 To UBound($auctions)-1 Local $objJson2 = $auctions[$i] ConsoleWrite(Jsmn_ObjGet($objJson2, "p")) Next EndIf When I transform the JSON string like this, it produces an output: #Include <JSMN.au3> $JSON='{"a":{"742597609":{"v":673,"p":4.91,"lb":"test1","av":58,"sl":11.6},"534165346":{"v":777,"p":5.66,"lb":"test2","av":58,"sl":13.3}},"b":16092018}' ;JSMN compatibility $JSON=StringRegExpReplace($JSON,'"\d{9}":','') $JSON=StringReplace($JSON,'{"a":{','{"a":[') $JSON=StringReplace($JSON,'}},','}],') ;produces ;$JSON='{"a":[{"v":673,"p":4.91,"lb":"test1","av":58,"sl":11.6},{"v":777,"p":5.66,"lb":"test2","av":58,"sl":13.3}],"b":16092018}' Local $objJson = Jsmn_Decode($JSON) If Jsmn_IsObject($objJson) Then Local $auctions = Jsmn_ObjGet($objJson, "a") For $i = 0 To UBound($auctions)-1 Local $objJson2 = $auctions[$i] ConsoleWrite(Jsmn_ObjGet($objJson2, "p")) Next EndIf What am I doing wrong ? Is it possible to get the auction details (like "p" in this example) without transforming the JSON string ?1 point -
A Non-Strict JSON UDF (JSMN)
Taz77 reacted to Fly By Night for a topic
If I wanted to load in the Events object and search through all the values of a key for a specific one, what method would you recommend? I wasn't sure how to do this optimally that is why i ended up just doing a While..Wend using the $i to increment onto the next key until i find the value i'm after. Also i wasn't sure if '["events"][' & $i & ']["event_id"]') <> "" was the correct method to check for end of keys. I realise what i'm after is a Jsmn_Search function that looks for a value and returns how to obtain it via Jsmn_Get. I did a test of copying key values into an array using Jsmn_Get then _StringBetween and Jsmn_Get was a lot faster on a test of about 1600 keys.1 point -
You can optimize this code (and maybe any code) to avoid do the same thing everytime in the loop. For example, you can get '["events"]' object and reuse it in the loop. And then you can aslo try to modify the code to get "[' & $i & ']" only once when the $i was changed. However, even you wrote the optimized code, I don't think it will run faster than _StringBetween. So don't try to compare with that.1 point
-
A Non-Strict JSON UDF (JSMN)
Taz77 reacted to robertcollier4 for a topic
Can it be possible to use put and get via JSON Dot Notation?1 point -
Perfect, right at the time i thought of buying the $400 n/Software json Activex the native and free udf comes around, thank you very much.1 point
-
A Non-Strict JSON UDF (JSMN)
Taz77 reacted to Fly By Night for a topic
Thanks! Wow, it's easy to do once you know the correct syntax. Thanks again for the UDF and your code above really helps me understand it more now1 point -
Using Jsmn_Get(), it's easy. I will put this function into the UDF later. #Include "JSMN.au3" Local $Json = '{"events":[{"world_id":2012,"map_id":873,"event_id":"659149D4-43EC-4DCB-A6BB-0B2D402B537B","state":"Warmup"},{"world_id":2012,"map_id":873,"event_id":"72F93CD8-94AC-4234-8D86-996CCAC76A46","state":"Warmup"},{"world_id":2012,"map_id":873,"event_id":"81F89AC2-4764-49CB-A4F1-8B7546201DC7","state":"Active"},{"world_id":2012,"map_id":873,"event_id":"FF71DE90-423B-4685-A343-83487A330C7A","state":"Active"}]}' Local $Obj = Jsmn_Decode($Json) ConsoleWrite(Jsmn_Get($Obj, '["events"][0]["world_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][0]["map_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][0]["event_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][0]["state"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][1]["world_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][1]["map_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][1]["event_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][1]["state"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][2]["world_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][2]["map_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][2]["event_id"]') & @LF) ConsoleWrite(Jsmn_Get($Obj, '["events"][2]["state"]') & @LF) Func Jsmn_Get($Var, $Key) If Not $Key Then Return $Var Local $Match = StringRegExp($Key, "(^\[([^\]]+)\])", 3) If IsArray($Match) Then Local $Index = Jsmn_Decode($Match[1]) $Key = StringTrimLeft($Key, StringLen($Match[0])) If IsString($Index) And Jsmn_IsObject($Var) And Jsmn_ObjExists($Var, $Index) Then Local $Ret = Jsmn_Get(Jsmn_ObjGet($Var, $Index), $Key) Return SetError(@Error, 0, $Ret) ElseIf IsNumber($Index) And IsArray($Var) And $Index >= 0 And $Index < UBound($Var) Then Local $Ret = Jsmn_Get($Var[$Index], $Key) Return SetError(@Error, 0, $Ret) Else Return SetError(1, 0, "") EndIf EndIf Return SetError(2, 0, "") EndFunc1 point
-
A Non-Strict JSON UDF (JSMN)
Taz77 reacted to Fly By Night for a topic
I'm trying to parse the data below, {"events":[{"world_id":2012,"map_id":873,"event_id":"659149D4-43EC-4DCB-A6BB-0B2D402B537B","state":"Warmup"}, {"world_id":2012,"map_id":873,"event_id":"72F93CD8-94AC-4234-8D86-996CCAC76A46","state":"Warmup"}, {"world_id":2012,"map_id":873,"event_id":"81F89AC2-4764-49CB-A4F1-8B7546201DC7","state":"Active"}, {"world_id":2012,"map_id":873,"event_id":"FF71DE90-423B-4685-A343-83487A330C7A","state":"Active"}]} The end result would be an array with 3 columns for map_id, event_id, and state filled with the relevant data. By striping '{"events":[' and ']}' from either end i managed to get the values of the first line/object but how do extract further items? I can't work out how to loop into the next line(s). Thanks for any help. My code isn't really worth showing hence no code example.1 point -
I wrote a helper function to get specific element in nested array/object returned from Jsmn_Decode() more easily. Here is the code and example: #Include "JSMN.au3" Local $Json = '{"key1" : "value1", "key2" : [true, ["a", "b"], {"key3", "obj_in_array"}]}' Local $Obj = Jsmn_Decode($Json) Jsmn_Get_ShowResult($Obj, '["key1"]') Jsmn_Get_ShowResult($Obj, '["key2"][0]') Jsmn_Get_ShowResult($Obj, '["key2"][1][0]') Jsmn_Get_ShowResult($Obj, '["key2"][2]["key3"]') Local $Json = '{"strange key []" : "uses \\uXXXX for unsupported char in the key", "key_nospace_1" : {"key_nospace_2" : "don''t need \" if the key has no space"} }' Local $Obj = Jsmn_Decode($Json) Jsmn_Get_ShowResult($Obj, '["strange key [\u005D"]') Jsmn_Get_ShowResult($Obj, '[key_nospace_1][key_nospace_2]') Jsmn_Get_ShowResult($Obj, '[error1]') Jsmn_Get_ShowResult($Obj, '[error2') Func Jsmn_Get_ShowResult($Var, $Key) Local $Ret = Jsmn_Get($Var, $Key) If @Error Then Switch @error Case 1 ConsoleWrite("Error 1: key not exists" & @LF) Case 2 ConsoleWrite("Error 2: syntax error" & @LF) EndSwitch Else ConsoleWrite($Key & " => " & VarGetType($Ret) & ": " & $Ret & @LF) EndIf EndFunc Func Jsmn_Get($Var, $Key) If Not $Key Then Return $Var Local $Match = StringRegExp($Key, "(^\[([^\]]+)\])", 3) If IsArray($Match) Then Local $Index = Jsmn_Decode($Match[1]) $Key = StringTrimLeft($Key, StringLen($Match[0])) If IsString($Index) And Jsmn_IsObject($Var) And Jsmn_ObjExists($Var, $Index) Then Local $Ret = Jsmn_Get(Jsmn_ObjGet($Var, $Index), $Key) Return SetError(@Error, 0, $Ret) ElseIf IsNumber($Index) And IsArray($Var) And $Index >= 0 And $Index < UBound($Var) Then Local $Ret = Jsmn_Get($Var[$Index], $Key) Return SetError(@Error, 0, $Ret) Else Return SetError(1, 0, "") EndIf EndIf Return SetError(2, 0, "") EndFunc1 point
-
Funny that I need such a UDF now. This has to be the best JSON UDF I've seen floating around the Forums. Thanks ward.1 point
-
A Non-Strict JSON UDF (JSMN)
Taz77 reacted to mmscripting for a topic
Hey Ward, fist of all thanks for JSON extension! I appreciate the work you spent to help this community with your programming skills! I am new to this forum and autoit is one of my personal interests so I would like to say "Hello everyone" . Maybe someone can help me with my question?: I want to query a JSON wheather service to get the actual wheater and for future use also the forecast. For this I use OperWheatherMap API and build my JSON, e.g. for today in Berlin: {"cod":"200","message":0.0268,"city":{"id":2950159,"name":"Berlin","coord":{"lon":13.41053,"lat":52.524368},"country":"DE","population":1000000},"cnt":1,"list":[{"dt":1368874800,"temp":{"day":13.22,"min":10.57,"max":13.22,"night":10.57,"eve":12.49,"morn":13.22},"pressure":1015.76,"humidity":100,"weather":[{"id":501,"main":"Rain","description":"mäßiger Regen","icon":"10"}],"speed":7.08,"deg":269,"clouds":92,"rain":7.75}]} My special interest lays in the params "temp":{"day":13.22,"min":10.57,"max":13.22 ... and "description":"mäßiger Regen" but I am not able to extract this information using JSMN. My code: #include <JSMN.au3> ; Anfrage von Wetter mit JSON Antwort: http://api.openweathermap.org/data/2.5/forecast/daily?q=Berlin&mode=json&units=metric&cnt=1&lang=de local $Json1 = '{"cod":"200","message":0.0268,"city":{"id":2950159,"name":"Berlin","coord":{"lon":13.41053,"lat":52.524368},"country":"DE","population":1000000},"cnt":1,"list":[{"dt":1368874800,"temp":{"day":13.22,"min":10.57,"max":13.22,"night":10.57,"eve":12.49,"morn":13.22},"pressure":1015.76,"humidity":100,"weather":[{"id":501,"main":"Rain","description":"mäßiger Regen","icon":"10"}],"speed":7.08,"deg":269,"clouds":92,"rain":7.75}]}' Local $objJson = Jsmn_Decode($Json1) If (Jsmn_IsObject($objJson)) Then ConsoleWrite('Data1:' & Jsmn_ObjGetKeys($objJson) & @CRLF) ConsoleWrite('Data2:' & Jsmn_ObjGet($objJson, "message") & @CRLF) ConsoleWrite('Data3:' & Jsmn_ObjGetCount($objJson) & @CRLF) ConsoleWrite('Data4:' & Jsmn_ObjExists($objJson, "message") & @CRLF) Else ConsoleWrite("Kein Objekt") EndIf The according console output: Data1: Data2:0.0268 Data3:5 Data4:True So the first level was queried successfully but if I want to query the params mentioned above I get an empty result: AutoIt: #include <JSMN.au3> ; Anfrage von Wetter mit JSON Antwort: http://api.openweathermap.org/data/2.5/forecast/daily?q=Berlin&mode=json&units=metric&cnt=1&lang=de local $Json1 = '{"cod":"200","message":0.0268,"city":{"id":2950159,"name":"Berlin","coord":{"lon":13.41053,"lat":52.524368},"country":"DE","population":1000000},"cnt":1,"list":[{"dt":1368874800,"temp":{"day":13.22,"min":10.57,"max":13.22,"night":10.57,"eve":12.49,"morn":13.22},"pressure":1015.76,"humidity":100,"weather":[{"id":501,"main":"Rain","description":"mäßiger Regen","icon":"10"}],"speed":7.08,"deg":269,"clouds":92,"rain":7.75}]}' Local $objJson = Jsmn_Decode($Json1) If (Jsmn_IsObject($objJson)) Then ConsoleWrite('Data1:' & Jsmn_ObjGetKeys($objJson) & @CRLF) ConsoleWrite('Data2:' & Jsmn_ObjGet($objJson, "day") & @CRLF) ConsoleWrite('Data3:' & Jsmn_ObjGetCount($objJson) & @CRLF) ConsoleWrite('Data4:' & Jsmn_ObjExists($objJson, "day") & @CRLF) Else ConsoleWrite("Kein Objekt") EndIf Local $objJson2 = Jsmn_Decode($objJson) Console: Data1: Data2: Data3:6 Data4:True Because this is my first contact with JSON I think that I am doing something wrong with the the function "Jsmn_ObjGet". But what am I doing wrong? Regards mmscripting1 point -
What for an impolite user! Thanks it works very fine! Randomly, I need it for Mt. Gox Too1 point
-
Try this code, then your will see every element is decoded succeed. #Include "JSMN.au3" Local $Json = BinaryToString(InetRead("http://data.mtgox.com/api/1/BTCUSD/depth"), 4) Local $Obj = Jsmn_Decode($Json) ConsoleWrite(Jsmn_Encode($Obj, $JSMN_PRETTY_PRINT)) Then why you got empty output? Because in your code, "$result[2][1]" is an array, so you can't use MsgBox to output it.1 point
-
1 point
-
You're right, seems to be Wards code and I would recommend to switch to Wards code as these functions support x64 as well (+ this is already DEP save).1 point
-
UEZ, you are giving me credit for base64 code but that code is not mine as far as I know. The only base64 code I have ever used in that form is Ward's and it's inside AutoItObject.au3, working in both x86 and x64 versions of interpreter. I have written base64 UDF code using Windows API for, but not this.1 point
-
Thanks for you suggestion - makes sense! Next release will check whether compression increases the size and skip to uncompressed binary automatically! Br, UEZ1 point
-
Now yes: it's perfect! Thank you... João Carlos.1 point
-
Updated to v0.99 -> added multi file support. Br, UEZ1 point
-
Fixed some bugs (no base64 conversation on small files and checkbox logic issues) and added DEP check to add program to the exclusion list to avoid hard crash. Edit: I will add the modified _Base64Encode() function by KaFu in the next release! Br, UEZ1 point
-
It crashes in the _Base64Encode() function. I've got DEP activated, and I guess you're missing a _MemVirtualAlloc() for the codebuffer there. Edit: Btw, this one came exactly at the right time and the "File to Hex Binary Converter" version went right into , thanks a lot! I'll switch to the Base64 on the next release. Edit #2: Add #include <Memory.au3> at the top and change the _Base64Encode() function to this ... Func _Base64Encode($Data, $LineBreak = 0) Local $Opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152" _ & "535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778" _ & "797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB6" _ & "33C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB633" _ & "83E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E806" _ & "0FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6" _ & "730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC0475" _ & "0C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000" Local $pProc = _MemVirtualAlloc(0, BinaryLen($Opcode), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]",$pProc) DllStructSetData($CodeBuffer, 1, $Opcode) $Data = Binary($Data) Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]") DllStructSetData($Input, 1, $Data) $LineBreak = Floor($LineBreak / 4) * 4 Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3) $OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4 Local $Ouput = DllStructCreate("char[" & $OputputSize & "]") DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), "ptr", DllStructGetPtr($Input), "int", BinaryLen($Data), "ptr", DllStructGetPtr($Ouput), "uint", $LineBreak) _MemVirtualFree($pProc, BinaryLen($Opcode), $MEM_DECOMMIT) Return DllStructGetData($Ouput, 1) EndFunc ;==>_Base64Encode1 point
-
Strange, because I'm using Win7 x64 in general, too! Which file your are converting and on which stage it is crashing (while compression or base64 converting)? What is the error code? Br, UEZ1 point
-
Very good, my sample image is now 384KB with your script! João Carlos.1 point
-
Your first version worked fine, this one crashes on my Win7-64bit while converting.1 point
-
Changed the code from binary string to base64 string to save some more bytes Br, UEZ1 point
-
@UEZ I have a sample image with 296 KB when converted with your script the size is 573 KB and with my script is 397 KB! João Carlos.1 point
-
Indeed, very similar script. Well, I implemented also a Base64 version but the compression wasn't better. Have a look here: Base64 version Either I missed something or it is as it is. This appears with Windows XP only. Just move these 2 lines _WinAPI_DeleteObject($Bmp_Logo) _WinAPI_DeleteObject($Bmp_Button) to Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($Bmp_Logo) _WinAPI_DeleteObject($Bmp_Button) GUIDelete($hGUI) Exit and should work. Btw, the button looks awful on WinXP Thanks for your feedback! Br, UEZ1 point
-
I wanted to try your example but when mouse is over bottom button, merlin disapears...1 point
-
Very similar to this script: I make use of Base64 encoding features, the compression is much better! João Carlos.1 point