Leaderboard
Popular Content
Showing content with the highest reputation on 10/18/2022 in all areas
-
Help File/Documentation Issues. (Discussion Only)
pixelsearch and one other reacted to jpm for a topic
I fix the doc and expand _IsPressed() to us directly $vk_* values as defined in WinAPIsvirkesConstants.au32 points -
Xml2Json UDF - Transform XML to JSON
AspirinJunkie reacted to TheXman for a topic
The tools & UDF's used to parse and process JSON are much more flexible and powerful than the ones for XML. In general, they are also much faster. So I created this Xml2Json UDF to tranform XML to JSON. It consists of 2 functions, _Xml2Json() and _XmlFile2Json(). ;================================================================================================= ; _Xml2Json($sXml, $sXsl = Default) ; ; Author: TheXman (https://www.autoitscript.com/forum/profile/23259-thexman/?tab=field_core_pfield_11) ; ; Description: Transform XML string to JSON ; Parameter(s): $sXml - A string containing a valid XML document. ; $sXsl - [optional] A string containing the XSL stylesheet used for transform. ; Return Value(s): Success - A string containing JSON ; Failure - "" and sets @error to a non-zero value. ; @error 1 = Unable to create XML object ; 2 = Unable to create XSL object ; 3 = Unable to parse XML. Make sure XML is valid. ; 4 = Unable to parse XSL. Make sure XSL is valid. ; 5 = XML Transform failed. Make sure you are using a valid v1.0 stylesheet. ; ; Remarks: MSXML 6.0, the COM component used to do the tranformations, only processes ; XSLT 1.0 stylesheets. If you pass a version 2.0+ stylesheet, you WILL get an ; error. ; ; The XSL stylesheet used by default came from: ; https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/ ; MIT License - Copyright (c) 2012 Bojan Bjelic ;================================================================================================= ;================================================================================================= ; _XmlFile2Json($sXmlFile, $sXsl = Default) ; ; Author: TheXman (https://www.autoitscript.com/forum/profile/23259-thexman/?tab=field_core_pfield_11) ; ; Description: Transform XML file to JSON ; Parameter(s): $sXmlFile - A string containing a valid XML document file path. ; $sXsl - [optional] A string containing the XSL stylesheet used for transform. ; Return Value(s): Success - A string containing the transformed JSON. ; Failure - "" and sets @error to a non-zero value. ; @error -1 = File does not exist ; 1 = Unable to create XML object ; 2 = Unable to create XSL object ; 3 = Unable to parse XML. Make sure XML is valid. ; 4 = Unable to parse XSL. Make sure XSL is valid. ; 5 = XML Transform failed. Make sure you are using a valid v1.0 stylesheet. ; ; Remarks: MSXML 6.0, the COM component used to do the tranformations, only processes ; XSLT 1.0 stylesheets. If you pass a version 2.0+ stylesheet, you WILL get an ; error. ; ; The XSL stylesheet used by default came from: ; https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/ ; MIT License - Copyright (c) 2012 Bojan Bjelic ;================================================================================================= The transformation is done by doing an XML Transform using a xml-to-json XSL stylesheet. If you want to use your own xml-to-json XSL stylesheet instead of the default one, then you can supply it in the 2nd parameter. The only caveat is that all values are transformed to strings. That means that numeric XML values will be returned as a strings. For example, the numeric value 10.50 will be returned as "10.50". The UDF comes with a couple of example scripts. One example script, which is below, just shows a sample transformation using the included sample XML file. The second example does the transformation and queries the transformed JSON for information. Example-01 ( uses the included sample XML file, Books.xml ) #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include "xml2json.au3" #include "jq.au3" ; (https://www.autoitscript.com/forum/files/file/502-jq-udf-a-powerful-flexible-json-processor/) example() Func example() Const $XML_FILE = "books.xml" Local $hTimer = -1 Local $sCmdOutput = "", _ $sJson = "" ;Initialize jq environment _jqInit("C:\Utils\JQ\jq-win64.exe") ;<== Path to jq exe If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to find jq executable - @error = " & @error) $hTimer = TimerInit() ;Convert XML to JSON $sJson = _XmlFile2Json($XML_FILE) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "_xmlfile2json() Error", "@error = " & @error) ConsoleWrite(StringFormat("Elapsed time to transform XML to JSON: %.3f seconds", TimerDiff($hTimer) / 1000) & @CRLF) ;Pretty-print JSON $sCmdOutput = _jqPrettyPrintJson($sJson, " ") If @error Then MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Pretty-print failed - @error = " & @error & " @extended = " & @extended) ConsoleWrite("ERROR:" & @CRLF & $sCmdOutput & @CRLF) Exit EndIf ConsoleWrite($sCmdOutput & @CRLF) EndFunc Output Elapsed time to transform XML to JSON: 0.003 seconds { "catalog": { "book": [ { "id": "bk101", "author": "Gambardella, Matthew", "title": "XML Developer's Guide", "genre": "Computer", "price": "44.95", "publish_date": "2000-10-01", "description": "An in-depth look at creating applications with XML." }, { "id": "bk102", "author": "Ralls, Kim", "title": "Midnight Rain", "genre": "Fantasy", "price": "5.95", "publish_date": "2000-12-16", "description": "A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world." }, { "id": "bk103", "author": "Corets, Eva", "title": "Maeve Ascendant", "genre": "Fantasy", "price": "5.95", "publish_date": "2000-11-17", "description": "After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society." }, { "id": "bk104", "author": "Corets, Eva", "title": "Oberon's Legacy", "genre": "Fantasy", "price": "5.95", "publish_date": "2001-03-10", "description": "In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant." }, { "id": "bk105", "author": "Corets, Eva", "title": "The Sundered Grail", "genre": "Fantasy", "price": "5.95", "publish_date": "2001-09-10", "description": "The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy." }, { "id": "bk106", "author": "Randall, Cynthia", "title": "Lover Birds", "genre": "Romance", "price": "4.95", "publish_date": "2000-09-02", "description": "When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled." }, { "id": "bk107", "author": "Thurman, Paula", "title": "Splish Splash", "genre": "Romance", "price": "4.95", "publish_date": "2000-11-02", "description": "A deep sea diver finds true love twenty thousand leagues beneath the sea." }, { "id": "bk108", "author": "Knorr, Stefan", "title": "Creepy Crawlies", "genre": "Horror", "price": "4.95", "publish_date": "2000-12-06", "description": "An anthology of horror stories about roaches, centipedes, scorpions and other insects." }, { "id": "bk109", "author": "Kress, Peter", "title": "Paradox Lost", "genre": "Science Fiction", "price": "6.95", "publish_date": "2000-11-02", "description": "After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum." }, { "id": "bk110", "author": "O'Brien, Tim", "title": "Microsoft .NET: The Programming Bible", "genre": "Computer", "price": "36.95", "publish_date": "2000-12-09", "description": "Microsoft's .NET initiative is explored in detail in this deep programmer's reference." }, { "id": "bk111", "author": "O'Brien, Tim", "title": "MSXML3: A Comprehensive Guide", "genre": "Computer", "price": "36.95", "publish_date": "2000-12-01", "description": "The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more." }, { "id": "bk112", "author": "Galos, Mike", "title": "Visual Studio 7: A Comprehensive Guide", "genre": "Computer", "price": "49.95", "publish_date": "2001-04-16", "description": "Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment." } ] } } Xml2Json UDF (2022-12-07).zip1 point -
Just comment line 1956 in autoit3wrapper.au3. I will do the same for the next release as the error is already shown in the console.1 point
-
GuiCtrlSetPos works using IDs not handles #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> ; Create GUI with a _GUICtrlListView control Global $hGUI = GUICreate("_GUICtrlListView", 700, 500, -1, -1, $WS_OVERLAPPEDWINDOW) Global $hListView = _GUICtrlListView_Create($hGUI, "", 100, 100, 500, 300, BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) GUISetState(@SW_SHOW, $hGUI) MsgBox(0, "Note intial ListView position (centered on the GUI)", "Press OK to try to move ListView to bottom right corner of the GUI window.") WinMove($hListView, "", 200, 200) ; or ControlMove($hListView, "", "", 200, 200) Sleep(1000) WinMove($hListView, "", 100, 100, 600, 400) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete()1 point
-
dBase udf and dll
Holmesware reacted to pixelsearch for a topic
It's not easy, because OP wrote above, in this link : * the GetSubRecord function skips the first byte of the record, that is the record delete mark. * IsRecordDeleted() missing function. I just can't understand why OP didn't give access to this crucial information. What's the use of the dll if you can't distinguish valid records from deleted ones when (or before) they are displayed ? Anyway, knowing the structure of a dbf/foxpro file, it's doable as you'll see in this reworked script : #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiScrollBars.au3> #include <dBase.au3> Global $hwnd, $g_idListView, $hDbf Example() Func Example() $sDbfName = "Test.dbf" $hwnd = GUICreate($sDbfName, 1000, 600, 250, 100, -1, $WS_EX_ACCEPTFILES) $hDbf = OpenDBF($sDbfName) $fldCnt = GetFieldCount($hDbf) $g_idListView = GUICtrlCreateListView("", 0, 0, 1000, 600) _GUIScrollBars_Init($g_idListView) _GUICtrlListView_AddColumn($g_idListView, "Del", 35) GUISetState(@SW_SHOW) Local $cnt = 0 Do $fld = GetFieldName($hDbf, $cnt) $len = GetFieldLenght($hDbf, $cnt) $len = $len*5 _GUICtrlListView_AddColumn($g_idListView, $fld, 60+$len) $cnt +=1 Until $cnt = $fldCnt Local $hFileOpen = FileOpen($sDbfName, 0 + 512) ; 0 = Read, 512 = ANSI If $hFileOpen = - 1 Then Exit MsgBox(0,"FileOpen", "opening error") ; Pos 8-9 Position of first data record ; Pos 10-11 Length of one data record, including delete flag FileSetPos($hFileOpen, 8, $FILE_BEGIN) ; on byte 8 $sRead = FileRead($hFileOpen, 4) ; read 4 bytes (8-9-10-11) $iPosFirstRecord = Asc(StringMid($sRead, 1, 1)) + 256 * Asc(StringMid($sRead, 2, 1)) $iRecordLength = Asc(StringMid($sRead, 3, 1)) + 256 * Asc(StringMid($sRead, 4, 1)) Local $sData, $iIndex = - 1 ; keep it always - 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $fldNr = 36 ; 1st column = 0 Local $vSearch = 4.90 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; For $i = 0 To GetRecordCount($hDbf) - 1 If StringInStr(GetSubRecord($hDbf, $i, $fldNr), $vSearch) > 0 Then $iIndex += 1 ; 0+ If $iIndex = 0 Then _GUICtrlListView_BeginUpdate($g_idListView) Local $iPosDeleted = $iPosFirstRecord + $i * $iRecordLength FileSetPos($hFileOpen, $iPosDeleted, $FILE_BEGIN) $sData = FileRead($hFileOpen, 1) = "*" ? " X|" : "|" For $j = 0 To $fldCnt - 1 $sData &= GetSubRecord($hDbf, $i, $j) & "|" Next GUICtrlCreateListViewItem(StringTrimRight($sData, 1), $g_idListView) EndIf Next If $iIndex > -1 Then _GUICtrlListView_EndUpdate($g_idListView) WinSetTitle($hWnd, "", WinGetTitle($hWnd) & " : " & $iIndex + 1 & " match") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE FileClose($hFileOpen) CloseDBF($hDbf) ExitLoop Case $g_idListView EndSwitch WEnd GUIDelete($hwnd) EndFunc The deleted records are flagged with "X" in an extra 1st column. In case you don't want them to appear at all, it should be easy for you to move some lines in the script. The only issue (hopefully) you may encounter could appear with this line : Local $hFileOpen = FileOpen($sDbfName, 0 + 512) ; 0 = Read, 512 = ANSI My foxpro file is ANSI, so I had to open it with 512 If your foxpro file needs another value for opening, then you'll find the different values in AutoIt help file, topic FileOpen() Please tell us if it worked for you, ok ? Good luck1 point -
dBase udf and dll
andrewGo reacted to pixelsearch for a topic
@Holmesware Unfortunately OP didn't show for years and as his dll code has been kept secret... Anyway, I tried the following and it seems to work fine, without calling his Search() function (which accepts only -1 as third parameter as you noticed, -1 means search in any column) but sometimes (many times !) we would like to search only in one column and return the rows matching that column. To achieve this, I commented the following lines in OP's file Search.au3 : ;~ $Array = DllStructCreate("DWORD[1000]") ; 1000 rows returned (max) in my case ;~ $recCnt = Search($hDbf, "*4.9400", -1, DllStructGetPtr($Array), DllStructGetSize($Array)) ;~ If $recCnt >0 Then ;~ $recNr = 1 ;~ $fldNr = 0 ;~ $index = 0 ;~ $subitem = 0 ;~ _GUICtrlListView_BeginUpdate($g_idListView) ;~ Do ;~ $rec = GetSubRecord($hDbf, DllStructGetData($Array,1,$recNr), $fldNr) ;~ GUICtrlCreateListViewItem($rec, $g_idListView) ;~ Do ;~ $rec = GetSubRecord($hDbf, DllStructGetData($Array,1,$recNr), $fldNr) ;~ _GUICtrlListView_SetItem($g_idListView, $rec, $index, $subitem) ;~ $fldNr += 1 ;~ $subitem += 1 ;~ Until $fldNr = $fldCnt ;~ $recNr += 1 ;~ $fldNr = 0 ;~ $index += 1 ;~ $subitem = 0 ;~ Until $recCnt == $index ;~ _GUICtrlListView_EndUpdate($g_idListView) ;~ EndIf And placed these lines instead : ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $fldNr = 0 ; 1st column = 0 Local $vSearch = 1000.55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $iIndex = - 1 ; keep it always - 1 For $i = 0 To GetRecordCount($hDbf) - 1 If StringInStr(GetSubRecord($hDbf, $i, $fldNr), $vSearch) > 0 Then $iIndex += 1 ; 0+ (first row got index 0) If $iIndex = 0 Then _GUICtrlListView_BeginUpdate($g_idListView) GUICtrlCreateListViewItem("", $g_idListView) For $j = 0 To $fldCnt - 1 _GUICtrlListView_SetItem($g_idListView, GetSubRecord($hDbf, $i, $j), $iIndex, $j) Next EndIf Next If $iIndex > -1 Then _GUICtrlListView_EndUpdate($g_idListView) The 2 lines where you indicate the searched column and what you're searching for are these ones : ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $fldNr = 0 ; 1st column = 0 Local $vSearch = 1000.55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Now in case you want, from time to time, search again in any column, then you could rework the whole code and, when $fldNr = - 1, switch back to OP's code etc... Timers showed same speed as OP's Search function in the dll (based on a dbf of 1000 rows and 64 cols) Good luck1 point -
While 1 WEnd CPU usage?
SkysLastChance reacted to Melba23 for a topic
Scoox, GUIGetMsg has its own built-in Sleep of about 15ms (it varies depending on CPU loading) so you do not need a separate command. A Sleep(10) is more than sufficient to keep any other tight loop from frying the CPU - and as any shorter time parameter is automatically extended to 10ms there is no point in going lower, although tests have proved that even few nanoseconds are sufficient to prevent this. All clear? M231 point