Leaderboard
Popular Content
Showing content with the highest reputation on 02/17/2023 in all areas
-
JSON UDF in pure AutoIt
robertocm reacted to AspirinJunkie for a topic
Introduction JSON is a pure data exchange format. Basically you only have to deal with JSON in 2 places in a program: Once when reading JSON data and once when outputting data. In between it should not really matter that the data used to be JSON or should be converted to it. You should not need any special intermediate structures but only the elements that the respective programming language provides anyway. This is exactly the approach of this UDF: There is the function _JSON_Parse(), which converts an arbitrary JSON string into (nested) pure AutoIt data types (Arrays, Maps, Strings, Numbers, Null, True, False). And on the other side we have the function _JSON_Generate(), which generates a JSON string from arbitrary (nested) AutoIt data structures. Import and export JSON So how to use - let`s give an example: Handling nested data structures JSON is often very nested. The resulting AutoIt data is therefore naturally also nested, which makes it somewhat cumbersome to process with pure AutoIt on-board methods. For this reason, the UDF comes with a few helper functions that make life with this data easier. One of them is _JSON_Get(), which allows you to access deeply nested data with a simple query syntax. On the other hand there is the function _JSON_addChangeDelete() with which you can (the name already says it) change, add and delete data. You can even easily create deeply nested structures with a single call. Again, here is a small example of how to use it: Strictly speaking, these functions should not even have "JSON" in their names, since they are generally applied to data structures in AutoIt. However, since they are often used in the JSON environment, we allow ourselves this small inaccuracy. Why should i give it a try? Probably the most common method to deal with JSON in AutoIt is the variant via JSMN. My minor dissatisfactions with this approach led me to write this UDF in the first place a few years ago. So the incentives are quite JSMN related: Parsing and extraction of data is faster than in JSMN. (Only if the JSON string makes heavy use of JSON escapes should JSMN be a bit faster in parsing, since the escapes are resolved later.) Editing the data is easier, because you don't need special commands for the JSMN intermediate structure but deal directly with AutoIt structures. Generating JSON is also simple: build your structure in AutoIt as you like and then let it generate a JSON string for you with _JSON_Generate(). The UDF is smaller (28kb vs. 45kb) The UDF is in pure AutoIt. You can directly customize any behavior as you like. >>sourcecode and download on github<<1 point -
Please refrain from posting this bs when a MOD told the poster not to do this anymore. Even better: simply don't reply at all!1 point
-
Script to get website data and save to file
SOLVE-SMART reacted to JLogan3o13 for a topic
As you can see from mikell's response above, we are more than happy to help with the first problem so long as you understand we're here to guide, not write it for you. Take what suggestions you receive and try something on your own. If you get stuck, post your code (even non-running) here and we will do our best to assist. I suggest beginning with the first bullet. If you search the forum there are numerous examples of obtaining a page's source that you can study and modify to your needs.1 point -
autoit error
SOLVE-SMART reacted to Jos for a topic
Ok ... If all you can share is "doesn't work" then I guess we're done.1 point -
Can't Click to Visible Text, Coordinates or something?
ioa747 reacted to phoenixhuynh09 for a topic
Hi Did you test this code? This is ControlCommand not Send("Tab"). ControlCommand("Toad for Oracle Database Login Version 10.6.", "", "[CLASS:TPageControl; INSTANCE:1]", "TabRight", "")1 point -
Reading excel workbook doesn't seem to work after the first read
NassauSky reacted to mistersquirrle for a topic
I don't have Excel to try it out, but I would suggest that you run this with some additional logging, and see if there's some errors along the way: #include <Excel.au3> $sFullRange = "A1:L100" $sFileOpenDialogM = @ScriptDir & "\RefQuestions.xlsx" ;~ WinMinimizeAll() ; or Send("#m") _Excel_GetSheetTotals() Func _Excel_GetSheetTotals() ;OPEN MAIN TEMPLATE FILE $prog_excel = _Excel_Open() If $prog_excel == 0 Or @error Then ConsoleWrite('Error opening excel: ' & @error & @CRLF) Exit EndIf $oWorkbookM = _Excel_BookOpen($prog_excel, $sFileOpenDialogM) ; If $oWorkbookM == 0 Or @error Then ConsoleWrite('Unable to open the specified excel file: ' & @error & @CRLF) ;~ MsgBox("", "Error", "Unable to open the specified excel file") Exit EndIf ;READ FULL SHEET VALUES TO ARRAY Local $read = _Excel_RangeRead($oWorkbookM, $oWorkbookM.Activesheet, $sFullRange, 1) If @error Then ConsoleWrite('Unable to RangeRead (' & $sFullRange & '): ' & @error & @CRLF) Exit EndIf $iIndexM = FindTotalRow($read) ;REMOVE BLANK ROWS FROM MAIN FILE (THEN ADD BLANK ROW) _Excel_RangeDelete($oWorkbookM.Activesheet, "A3:L" & ($iIndexM)) If @error Then ConsoleWrite('Unable to RangeDelete (' & "A3:L" & ($iIndexM) & '): ' & @error & @CRLF) Exit EndIf _Excel_RangeInsert($oWorkbookM.ActiveSheet, "3:3") If @error Then ConsoleWrite('Unable to RangeInsert (' & "3:3" & '): ' & @error & @CRLF) Exit EndIf ;RE-READ FULL SHEET VALUES TO ARRAY Local $read = _Excel_RangeRead($oWorkbookM, Default, "A1:L4", 1) If @error Then ConsoleWrite('Unable to RangeRead (' & "A1:L4" & '): ' & @error & @CRLF) Exit EndIf ConsoleWrite("$read After deleting blank rows: " & $read & @CRLF) _ArrayDisplay($read, "After deleting blank rows") $iIndexM = FindTotalRow($read) MsgBox(0, "Notice", "Application Doesn't Reach This Point: " & $iIndexM) EndFunc ;==>_Excel_GetSheetTotals Func FindTotalRow($read) Local $iColtoSrch = 0 Local $sSearch = "TOTALS" Global $iIndex = _ArraySearch($read, $sSearch, 0, 0, 0, 1, 1, $iColtoSrch) If @error Then MsgBox($MB_SYSTEMMODAL, "Not Found So Exiting", '"' & $sSearch & '" was not found on column ' & $iColtoSrch & '.*') Exit EndIf Return $iIndex EndFunc ;==>FindTotalRow What's the output? Any errors? If so, looking up the error meanings in the help file, do you see why it's not working?1 point -
better: Run(@ComSpec & ' /c mklink /j "' & $dest & '" "' & $source & '"') //Run('mklink /j "' & $dest & '" "' & $source & '"')1 point
-
He's trying to get the JSON in the second snippet into his AutoIt code (first snippet) to send as a request: At least that's my take on the request. First of all, your JSON is not valid, JSON does NOT support comments, like //Incident Business Object ID. You need to remove all of those. As for then putting the multiline JSON into your script, I recommend that you run the JSON through a minifier, like: https://codebeautify.org/jsonminifier With the 'comments' removed, it outputs this: {"busObId":"6dd53665c0c24cab86870a21cf6434ae","Fields":["6ae282c55e8e4266ae66ffc070c17fa3"],"filters":[{"fieldId":"9365a6098398ff2551e1c14dd398c466d5a201a9c7","operator":"equals","value":"Incident"},{"fieldId":"83c36313e97b4e6b9028aff3b401b71c","operator":"equals","value":"1"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"New"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"Assigned"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"In Progress"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"Pending"},{"fieldId":"5eb3234ae1344c64a19819eda437f18d","operator":"equals","value":"Reopened"}]} That should have no issues inserting into AutoIt as long as it's enclosed with a single quote: '1 point
-
0 points