Leaderboard
Popular Content
Showing content with the highest reputation on 04/02/2013 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
-
How is using RunWait a better option? It will pause the script until you exit the program you started, so when does the ControlClick get activated?1 point
-
So do I. There will be a new release when Jon decides - until then you will have to live with the release and current Beta versions. And for various reasons, which I will not go into in detail, any new release will almost certainly only have a subset of the advances trialled in the Alpha releases of last year. So I would advise people not get used to using any/all of the features introduced in those Alpha versions in their code - or they may find that they have created problems for themselves when a new release does come along which does not support them. M231 point
-
Usually you use a database for this kind of data exchange.1 point
-
That's really some old version. What you should do is download latest version, you can find link to download page in the first post of this thread.1 point
-
Building a bitmap from random color data?
nullschritt reacted to PhoenixXL for a topic
Here we go #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <Constants.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 ;ARGB Local $aColors[11] For $i = 0 To UBound($aColors) - 1 $aColors[$i] = RandomColor() Next $iPic = CreateGUI() Main(50, $aColors, 50, $iPic) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE Sleep(10) WEnd GUIDelete() _GDIPlus_Shutdown() Func RandomColor() Return Random(0, 0xFFFFFF, 1) EndFunc ;==>RandomColor Func CreateGUI() GUICreate(StringTrimRight(@ScriptName, 4), 600, 400) $iPic = GUICtrlCreatePic('', 0, 0, 600, 400, $SS_BITMAP) Return $iPic EndFunc ;==>CreateGUI Func Main($iRectWidth, $aColors, $iPixelLen, $iPic) If Not IsInt($iRectWidth) Then $iRectWidth = Int($iRectWidth) Local $iWidth = (Floor($iRectWidth / 2) + Mod($iRectWidth, 2)) * $iPixelLen, $iHeight = Floor($iRectWidth / 2) * $iPixelLen Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp) Local $iUBound = UBound($aColors) Local $aBrush = CreateArrayBrush($aColors) Local $iBrush = 0 For $iY = 0 To $iHeight Step $iPixelLen For $iX = 0 To $iWidth Step $iPixelLen _GDIPlus_GraphicsFillRect($hGfx, $iX, $iY, $iPixelLen, $iPixelLen, $aBrush[$iBrush]) $iBrush += 1 If $iBrush = $iUBound Then $iBrush = 0 Next Next ;Image Controls Accept HBitmap Objects $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap( $hBmp ) GUICtrlSendMsg( $iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap) ;Memory Release _WinAPI_DeleteObject($hHBitmap) For $i = 0 To $iUBound - 1 _GDIPlus_BrushDispose($aBrush[$i]) Next _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageDispose($hBmp) EndFunc ;==>Main ;From GDIP library Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $GDIP_STATUS = $aResult[0] Return $aResult[6] EndFunc ;==>_GDIPlus_BitmapCreateFromScan0 Func CreateArrayBrush($aColors) Local $iUBound = UBound($aColors) Local $aBrush[$iUBound] For $i = 0 To $iUBound - 1 $aBrush[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $aColors[$i]) Next Return $aBrush EndFunc ;==>CreateArrayBrushThumbs up if it helped Regards1 point -
Could you also check what version of WinHttp.au3 you use?1 point
-
Need to build an auto-replace text files
DucViet321 reacted to abberration for a topic
This probably isn't what you need, but I whipped up a quick example for a game: #include <GUIConstants.au3> #include <array.au3> #include <GuiMenu.au3> Global $correct, $incorrect $Form1 = GUICreate("Q&A", 479, 231) $Label1 = GUICtrlCreateLabel("", 24, 24, 428, 41) $Radio1 = GUICtrlCreateRadio("", 24, 72, 113, 17) $Radio2 = GUICtrlCreateRadio("", 24, 96, 113, 17) $Radio3 = GUICtrlCreateRadio("", 24, 120, 113, 17) $Radio4 = GUICtrlCreateRadio("", 24, 144, 113, 17) $Button1 = GUICtrlCreateButton("Submit", 328, 184, 75, 25, 0) $Label2 = GUICtrlCreateLabel("Correct: 0", 24, 184, 70, 17) $Label3 = GUICtrlCreateLabel("Incorrect: 0", 24, 200, 70, 17) GUISetState(@SW_SHOW) _Question() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _CheckAnswer() _Question() EndSwitch WEnd Func _Question() $iSize = IniReadSectionNames(@ScriptDir & "\data.txt") ;~ _ArrayDisplay($iSize) $rNum = Random(1, $iSize[0], 1) $c1 = IniRead(@ScriptDir & "\data.txt", $iSize[$rNum], "Choice1", "") $c2 = IniRead(@ScriptDir & "\data.txt", $iSize[$rNum], "Choice2", "") $c3 = IniRead(@ScriptDir & "\data.txt", $iSize[$rNum], "Choice3", "") $c4 = IniRead(@ScriptDir & "\data.txt", $iSize[$rNum], "Choice4", "") GUICtrlSetData($Label1, $iSize[$rNum]) GUICtrlSetData($Radio1, $c1) GUICtrlSetData($Radio2, $c2) GUICtrlSetData($Radio3, $c3) GUICtrlSetData($Radio4, $c4) EndFunc Func _CheckAnswer() $c1 = GUICtrlRead($Radio1) $c2 = GUICtrlRead($Radio2) $c3 = GUICtrlRead($Radio3) $c4 = GUICtrlRead($Radio4) $question = GUICtrlRead($Label1) $correctAns = IniRead(@ScriptDir & "\data.txt", $question, "Correct", "") $ans = "" If $c1 = 1 Then $ans = ControlGetText($Form1, "", $Radio1) ElseIf $c2 = 1 Then $ans = ControlGetText($Form1, "", $Radio2) ElseIf $c3 = 1 Then $ans = ControlGetText($Form1, "", $Radio3) ElseIf $c4 = 1 Then $ans = ControlGetText($Form1, "", $Radio4) Else MsgBox(0, "Error", "You did not select an answer") EndIf If $ans = $correctAns Then MsgBox(0, "Congrautlations", "You got it right!") $correct += 1 GUICtrlSetData($Label2, "Correct: " & $correct) Else MsgBox(0, "Incorrect", "Sorry, but the correct answer was: " & $correctAns) $incorrect += 1 GUICtrlSetData($Label3, "Incorrect: " & $incorrect) EndIf EndFunc Then create a file called Data.txt and put this code in it: [What is the name of the cat?] Choice1=Doremon Choice2=Kitten Choice3=Cute Choice4=Dog Correct=Doremon [what is the name of the dog?] Choice1=Doremon Choice2=Kitten Choice3=Cute Choice4=Puppy Correct=Puppy1 point -
Need to build an auto-replace text files
DucViet321 reacted to FireFox for a topic
I guess something like that (not tested) : Local Const $aQuestion = StringSplit(FileRead("s.txt"), @CrLf & @CrLf, 1) Local $sOutput = "", $iRightAnswer = 0 For $i = 1 To $aQuestion[0] $aSentense = StringSplit($aQuestion[$i], @CrLf, 1) For $i2 = 1 To $aSentense[0] If $i2 = 1 Then $sOutput &= "Question: " & StringTrimLeft($aSentense[$i2], StringInStr($aSentense[$i2], ".", 2)) & @CrLf ContinueLoop EndIf $sOutput &= "Choice: " If StringLeft($aSentense[$i2], 1) = "*" Then $aSentense[$i2] = StringTrimLeft($aSentense[$i2], 1) $iRightAnswer = $i2 - 1 EndIf $sOutput &= $aSentense[$i2] & @CrLf Next $sOutput &= "Correct: " & $iRightAnswer & @CrLf & @CrLf Next FileWrite("s2.txt", $sOutput) Note: Input file s.txt Edit: too late >_< Br, FireFox.1 point -
Need to build an auto-replace text files
DucViet321 reacted to Melba23 for a topic
DucViet, Something like this: #include <File.au3> #include <Array.au3> ; Just for display ; Read in file Global $aLines _FileReadToArray("Test.txt", $aLines) ; Declare result array Global $aNewLines[1] = [0] For $i = 1 To $aLines[0] ; Look for a question If StringRegExp($aLines[$i], "^\d+\.") Then ; Look for the answer For $j = 1 To 4 If StringLeft($aLines[$i + $j], 1) = "*" Then ; Found it - remove leading * $aLines[$i + $j] = StringTrimLeft($aLines[$i + $j], 1) ; And note place $iAnswer = $j ExitLoop EndIf Next ; Where to insert this section $iIndex = $aNewLines[0] + 1 ; ReDim teh array $aNewLines[0] += 7 ReDim $aNewLines[$aNewLines[0] + 1] ; Insert the existing lines For $j = 0 To 4 $aNewLines[$iIndex + $j] = $aLines[$i + $j] Next ; insert the new answer line $aNewLines[$iIndex + $j] = "Correct:" & $iAnswer ; And a blank $aNewLines[$iIndex + $j + 1] = "" _ArrayDisplay($aNewLines, $i) ; Just for display EndIf Next ; Write new file _FileWriteFromArray("NewTest.txt", $aNewLines, 1) will change this: 1. What is the name of the cat? *Doremon Kitten Cute Dog 2.What is the name of the dog? Doremon Kitten Cute *Puppy into this: 1. What is the name of the cat? Doremon Kitten Cute Dog Correct:1 2.What is the name of the dog? Doremon Kitten Cute Puppy Correct:4 I hope that helps. M231 point -
As far as I know running AutoIt on Windows 8 isn't supported. Besides that, what version of AutoIt you run?1 point
-
Hi, Welcome to the autoit forum Here is the right syntax : ControlClick("[TITLE:Order Tracking Main;CLASS:WindowsForms10.window.8.app.0.143a722_r15_ad1]", "", "[CLASS:WindowsForms10.BUTTON.app.0.143a722_r15_ad1; INSTANCE:1]")I suggest you to read the help file for this function if it's not already done. In particular this. If you have any questions concerning the syntax please ask Edit: You should use the AutoIt3Info tool included in the autoit setup package which is designed to be used with the autoit functions. Br, FireFox.1 point
-
MrVietA2, Firstly, I suggest you create your buttons outside of the area covered by the ListView. Secondly, if you want an editable ListView I suggest you look at the Beta version of my GUIListViewEx UDF that you can find here. By using it I have reduced your code to the following, which looks a lot simpler to me: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx_Mod.au3" Global $hListView _GUI() Func _GUI() Global $hGui = GUICreate("script", @DesktopWidth - 380, @DesktopHeight - 250, -1, -1) GUISetBkColor(0xC4C4C4) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") Global $Button1 = GUICtrlCreateButton("Button 1", 408, @DesktopHeight - 350, 121, 49) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") Global $Button2 = GUICtrlCreateButton("Button2", 720, @DesktopHeight - 350, 121, 49) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") Create_Listview() GUISetState(@SW_SHOW) Local $aLV_Array = _GUIListViewEx_ReadToArray($hListView) _GUIListViewEx_Init($hListView, $aLV_Array, 0, 0, 2) _GUIListViewEx_DragRegister(True, False, False) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit EndSwitch _GUIListViewEx_Edit() WEnd EndFunc ;==>_GUI Func Create_Listview() $hListView = _GUICtrlListView_Create($hGui, "", 5, 5, @DesktopWidth - 400, @DesktopHeight - 400, $LVS_REPORT) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_AddColumn($hListView, "Column 1", 175) _GUICtrlListView_AddColumn($hListView, "Column 2", 175) _GUICtrlListView_AddColumn($hListView, "", 175) _GUICtrlListView_AddColumn($hListView, "", 175) For $i = 1 To 20 _GUICtrlListView_AddItem($hListView, "") _GUICtrlListView_AddSubItem($hListView, $i - 1, "", 1) _GUICtrlListView_AddSubItem($hListView, $i - 1, "", 2) _GUICtrlListView_AddSubItem($hListView, $i - 1, "", 3) Next EndFunc ;==>Create_ListviewJust doubleclick in the ListView to enter "edit" mode. M231 point
-
How about ContinueLoop?1 point
-
I started using autoit some years ago and to be honest i started using it for game reasons. When i first came to this forum i started fighting with a guy(Valik) and getting banned because i didn't knew the rules and wasn't experienced enough with this language and my account was locked. Some years later i used this forum again. I was following the forum and the language and saw very good updates and upgrades. When i came up with some more advanced topics i found out that that guy that had locked my account was helping me. Following the topics in general and example section i was looking a very good team leading well autoit. It's been 6 months now that i can't find any good updates now or any usefull example scripts. I don't know who's fault this is but i dont like it. Instead of watching the dev team posting some good examples, giving good advices or helping people with their problem, i see the dev team locking threads, editing them(witch shouldn't be allowed even a topic break the rules) and banning people. And why the hell you have moderators then? I am sorry but i can't find a logic here I just found out that one best devs(trancexx) is not a dev anymore, some months ago i found out that Valik is inactive and i see some devs that are usefull only for locking threads continuing being devs. I like autoit and i use it everyday but if it is going to continue like this, it is not going to end up very well1 point