Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/12/2019 in all areas

  1. jchd

    RegExp help

    Successive empty captures in the resulting array are there because there is a difference between Perl regex and legacy PCRE1 regex (which current AutoIt implements). PCRE2 (is 4 year old already) now conforms to Perl with respect of unwanted empty captures but it isn't the version AutoIt uses. Yet you can overcome this behavior difference by using the (?| ) construct: Local $s = "artist=MyArtist&title=MySong&album=TheBestOf&year=2019&type=Music" Local $r = StringRegExp($s, "(?|(?:artist=([^&]*))|(?:title=([^&]*))|(?:album=([^&]*))|(?:year=([^&]*))|(?:type=([^&]*)))", 3) _ArrayDisplay($r) But that doesn't solve the issue of unordered, extra or missing elements. To do that you need another idea: Local $aData = [ _ "title=MySong&album=TheBestOf&year=2019&artist=MyArtist&type=Music", _ "comment=this is pure junk&title=MySong&year=2019&artist=MyArtist&album=TheBestOf&type=Music", _ "title=MySong&year=2019&comment=excellent title&artist=MyArtist&album=TheBestOf" _ ] Local Static $aKeys = ["artist", "album", "year", "title", "type", "comment"] Local $d = ObjCreate("Scripting.Dictionary"), $dummy For $s In $aData $dummy = Execute(StringRegExpReplace($s, "(\w+)=([^&]*)&?", "$d.Add(""$1"", ""$2"") & ") & '""') For $k In $aKeys ConsoleWrite($k & " -> " & $d.Item($k) & @LF) Next ConsoleWrite(@CRLF) $d.RemoveAll Next This way you can add as many potential elements and pick them in fixed order.
    2 points
  2. Basically it's been a while since I did any coding and after battling depression (still fighting) I'm starting to feel more like myself and feel the desire to do things I once loved. With that being said I would absolutely love for anyone and everyone to ask me for help on projects or anything really. I'm pretty well versed in AutoIt, I would also like to think I know my way around PHP, HTML, and a few other things. It doesn't matter the project or the question; I just want to get back into coding; picturing things in my head and bringing them to life on a screen. Hope this doesn't come off weird or anything, just seems like a good way to get back into coding seeing as how I have no real ideas for any tools or projects to create at the moment. I'm also killing two birds with one stone; I struggle with social interaction and hope working with people of various projects/problems will help me fine tune my programming and social skills! Thanks for taking the time to read my post, I'm very happy to be apart of this community for as long as I can remember (at least 8 years).
    1 point
  3. iamtheky

    RegExp help

    damn mikell I was seconds away, I'd still give you a regex, but only in arrayfindall to delete the unwanted fields. #include<array.au3> Local $str = "artist=MyArtist&album=TheBestOf&comment=this is junk&title=MySong&year=2019&Comment2=this year was junk&type=Music" local $a[0][2] _ArrayAdd($a , $str , 0 , "=" , "&") _ArrayDelete($a , _ArrayToString(_ArrayFindAll($a , "[^artist|title|album|year|type]" , 0 , 0 , 0 , 3) , ";")) _ArrayDisplay($a)
    1 point
  4. jchd

    RegExp help

    I was just trying to explin why a regex can't go back and forth in the subject string to capture elements found in varying order but expected to be process in fixed order. This was the actual OP question. The method is generic and doesn't rely on an easy to split pattern, like in this particular case. And regexes are sooo friendly...
    1 point
  5. mikell

    RegExp help

    Why use regex when it is not necessary ? #include <Array.au3> $s = 'artist=MyArtist&title=MySong&album=TheBestOf&year=2019&type=Music' Local $array[0][2] _ArrayAdd($array, StringReplace(StringReplace($s, "=", "|"), "&", @crlf)) _ArrayDisplay($array)
    1 point
  6. @supraaxdd When replying, can you please stop quoting the entire previous post? Everyone can read what the other person posted, so there's no reason to quote the thing in its entirety. If you must quote something, quote only the information the pertains to your reply and discard the rest. Also, there's no need to quote someone's code unless you've modified it in some way. You're just making it harder for everyone else to follow the flow of the thread by unnecessary over-quoting.
    1 point
  7. Hi @robertocm, thanks for testing and posting your results... For what I understand, in the way that you have used, you trap events coming from the html "document" object, and then you have to check further, in the event function of the document, from which specific element the event was fired using a series of if ... then statements. This is also a way to go, but if you want to trap events, directly from a specific DOM object, then you have to pass a reference of that specific object to the AutoIt ObjEvent() function. Also, not all and not always the events fired by a specific child dom object are "bubbled" up to the top DOM object, that is the "document" object. In that case you are not able to catch the event through the document object because it doesn't receive it from the child elements. Have a look to the "Background" session of this link (https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752045(v%3dvs.85)) for a better explanation of how events are forwarded up in the DOM hierarchy. Hi @supraaxdd, the variable $sHTML is not "reassigned" each time, but since is used the concatenation operator (that is the &= sign) and not the assignment operator (that is the = sign) the value is "appended" to the current content of the variable and is not overwritten.
    1 point
  8. Dear Chimp, Below is code from your previous comment here only small changes trying to capture document events from an html form in the embedded webcontrol i'm finding this approach simpler to understand, and seems to work ok. For sure, i'm not understanding some concepts? Thanks for your comments #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $g_idGUIEdit Example() Exit ; End of our Demo. Func Example() Local $hGUIMain = GUICreate("Event Test", 1000, 600) $g_idGUIEdit = GUICtrlCreateEdit("", 5, 405, 990, 175) ; GUICtrlSetBkColor(-1, 0x000000) ; GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetFont(-1, 9, 400, -1, 'Courier New') GUICtrlCreateLabel("Below are some Browser events 'captured' from the above web page by AutoIt", 5, 385, 990, 20) Local $idGUIExit = GUICtrlCreateButton(" Close and exit", 5, 580, 990, 15) GUISetState() ;Show GUI ; We prepare the Internet Explorer as our test subject Global $oIE = ObjCreate("Shell.Explorer.2") $hIE = GUICtrlCreateObj($oIE, 5, 5, 990, 380) ; <- insert $oIE in the AutoIt GUI ; Here we load an example Web page just to have something viewed in the browser ;$oIE.navigate('http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onmousemoveEX.htm') ;>>>> ;These lines from: Chimp, Jan 2017 (edited) ;Who is Who ? (a little drag&drop game) ;https://www.autoitscript.com/forum/topic/186422-who-is-who-a-little-dragdrop-game/ ;Global $oIE = ObjCreate("Shell.Explorer.2") ; Create a BrowserControl ;Local $hGUI = GUICreate("", 660, 600, 30, 30) ;GUICtrlCreateObj($oIE, 0, 0, 660, 600) ; Place BrowserControl on the GUI ;GUISetState() ;Show GUI $oIE.navigate('about:blank') ; file:///' & @ScriptDir & '\WhoIsWho.html') While Not String($oIE.readyState) = 'complete' ; wait for about:blank Sleep(100) WEnd ; this waits till the document is ready to be used (portion of code from IE.au3) While Not (String($oIE.readyState) = "complete" Or $oIE.readyState = 4) Sleep(100) WEnd While Not (String($oIE.document.readyState) = "complete" Or $oIE.document.readyState = 4) Sleep(100) WEnd $oIE.document.Write(_GetHTML()) ; inject lising directly to the HTML document: $oIE.document.close() ; close the write stream $oIE.document.execCommand("Refresh") While Not String($oIE.readyState) = 'complete' ; wait for readyState after a refresh Sleep(100) WEnd $oDocument = $oIE.document ;>>>> ;~ Sleep(1000) ; Give it some time to load the web page ;~ Do ; wait for document ;~ Sleep(250) ;~ $oDocument = $oIE.document ;~ Until IsObj($oDocument) ; + Scripting Object Interfaces ; | --------------------------- ; | https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx ; | ; +--> HTMLDocumentEvents2 interface (catch OnClick, OnMouseOver, .... etc ; ----------------------------- ; https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx ; Global $oEventObject = ObjEvent($oDocument, "IEEvent2_", "HTMLDocumentEvents2") If @error Then MsgBox($MB_OK, "AutoIt COM Test", _ "ObjEvent: Can't use event interface 'HTMLDocumentEvents2'. Error code: " & Hex(@error, 8)) Exit EndIf ; GUISwitch($hGUIMain) ; Switch back to our GUI in case IE stole the focus ; Waiting for user to close the GUI. Local $iMsg While 1 $iMsg = GUIGetMsg() If $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $idGUIExit Then ExitLoop WEnd $oEventObject.Stop ; Tell IE we don't want to receive events. $oEventObject = 0 ; Kill the Event Object $oIE = 0 ; Remove IE from memory (not really necessary). GUIDelete() ; Remove GUI EndFunc ;==>Example ; A few Internet Explorer Event Functions ; ( reference to the Event Obj interface: ) ; ( https://msdn.microsoft.com/en-us/library/aa703876(v=vs.85).aspx ) ; Volatile Func IEEvent2_onClick($oEvent) ConsolePrint("mouse click: " & $oEvent.clientX & ',' & $oEvent.clientY & ' on ' & $oEvent.srcElement.NodeName & ' id: ' & $oEvent.srcElement.id) If $oEvent.srcElement.NodeName = "INPUT" Then If $oEvent.srcElement.type = "radio" Or $oEvent.srcElement.type = "checkbox" Then If $oEvent.srcElement.checked=true Then ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " True") Else ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " False") EndIf EndIf EndIf EndFunc ;==>IEEvent2_onClick Volatile Func IEEvent2_onDblClick($oEvent) ConsolePrint("mouse DoubleClick: @" & $oEvent.clientX & ',' & $oEvent.clientY) EndFunc ;==>IEEvent2_onDblClick ;~ Volatile Func IEEvent2_onMouseMove($oEvent) ;~ ConsolePrint("mouse moved to:" & @TAB & "Xpos = " & $oEvent.clientX & @TAB & "Ypos = " & $oEvent.clientY) ;~ EndFunc ;==>IEEvent2_onMouseMove Func ConsolePrint($sMsg) Local Const $iMaxLines = 9 ; keep last 9 log lines only $sMsg = @HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & $sMsg & @CRLF $sMsg = StringReplace(GUICtrlRead($g_idGUIEdit) & $sMsg, @CR, @CR) If @extended > $iMaxLines Then ; more than $iMaxLines $sMsg = StringMid($sMsg, StringInStr($sMsg, @CR, 0, -1 * $iMaxLines) + 2) EndIf GUICtrlSetData($g_idGUIEdit, $sMsg) EndFunc ;==>ConsolePrint Func _GetHTML() ;form html code from: Marc Clifton, 16 Feb 2013, https://www.codeproject.com/Articles/547451/WebBrowser-Element-Events-and-Values Local $sHTML = _ "<!DOCTYPE HTML>" & @CRLF & _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ "<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ "<title>Test</title>" & @CRLF & _ "</head>" & @CRLF & _ "<body>" & @CRLF & _ '<button type="button" id="btnMenu">=</button>' & @CRLF & _ '<button type="button" id="btnClose">X</button>' & @CRLF & _ '<form>' & @CRLF & _ 'First name: <input id="firstname" type="text" name="firstname"/><br/>' & @CRLF & _ 'Last name: <input id="lastname" type="text" name="lastname"/><br/>' & @CRLF & _ 'Password: <input id="password" type="password" name="pwd"/><br><br/>' & @CRLF & _ '<input type="radio" id="male" name="sex" value="male"/>Male<br/>' & @CRLF & _ '<input type="radio" id="female" name="sex" value="female"/>Female<br/><br/>' & @CRLF & _ '<input type="checkbox" id="bike" name="vehicle" value="Bike"/>I have a bike<br/>' & @CRLF & _ '<input type="checkbox" id="car" name="vehicle" value="Car"/>I have a car <br/><br/>' & @CRLF & _ '<input type="button" id="ok" value="OK"/><br/>' & @CRLF & _ '<input type="button" id="cancel" value="Cancel"/><br/><br/>' & @CRLF & _ '</from>' & @CRLF & _ "</body>" & @CRLF & _ "</html>" Return $sHTML EndFunc ;==>_GetHTML Update (Sept 2022): i got ideas from here for testing with excel vba: trying to get changed text in WebBrowser form: https://stackoverflow.com/a/73939147/6406135 Attached the excel file, if someone is interested Updated excel file: Oct 15, 2022 WebBrowser_Control_tests_202209.xlsm
    1 point
  9. I'm sure this is inconsequential but I recently tried to make an autoit script for monitoring a log file created by a program and found this thread extremely helpful (I had most of it down but I was having trouble with getting the editbox to accept the entire log file and this helped in that regard with the "GUICtrlSetLimit(-1, 0x7FFFFFFF)" function). I found that using the "@extended" macro helped in making sure I always had the correct position within the file I was monitoring. I have added/changed the script to work with the intended effect. I thought I would post here in case anyone else found themselves in need of monitoring a log file. ;Coded by UEZ Build 2010-06-30, tweaked by KaFu ;-), then again by KB. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $iMemo, $new_line $width = 1024 $height = 600 $hGUI = GUICreate("Realtime Log Reader by UEZ & KaFu 2010", $width, $height, -1, -1, Default, $WS_EX_TOPMOST) $iMemo = GUICtrlCreateEdit("", 0, 0, $width, $height, $ES_AUTOVSCROLL + $WS_VSCROLL + $WS_HSCROLL + $ES_READONLY) GUICtrlSetLimit(-1, 0x7FFFFFFF) GUICtrlSetFont($iMemo, 8.5, 400, 0, "Lucida Console") GUISetState() If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then $file = $CmdLine[1] Else $file = @WindowsDir & "\WindowsUpdate.log" ;$file = @ScriptDir & "\WindowsUpdate.log" EndIf $hFile = _FileOpen_Wrapper($file) $txt = FileRead($hFile) $fs = FileGetSize($file) $OrigCount = @Extended FileClose($hFile) ConsoleWrite($txt) _GUICtrlEdit_SetText($iMemo, $txt) _GUICtrlEdit_LineScroll($iMemo, 0, 0xfffffff) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While Sleep(1000) $fs_new = FileGetSize($file) If $fs < $fs_new Then $hFile = _FileOpen_Wrapper($file) If $hFile <> -1 Then FileSetPos($hFile, $OrigCount, 0) $new_line = FileRead($hFile) FileClose($hFile) $NewCount = @extended _GUICtrlEdit_AppendText($iMemo, $new_line) $OrigCount = $OrigCount + $NewCount $fs = $fs_new EndIf $new_line = "" EndIf WEnd Func _Exit() GUIDelete($hGUI) Exit EndFunc ;==>_Exit Func _FileOpen_Wrapper($file) $hFile = -1 $timer = TimerInit() While $hFile = -1 $hFile = FileOpen($file,128) If $hFile <> -1 Then ExitLoop Sleep(100) If TimerDiff($timer) > 5000 Then MsgBox(48, "Access Error", "File" & @CRLF & $file & @CRLF & "could not be opend in 5 seconds...") Exit EndIf WEnd Return $hFile EndFunc ;==>_FileOpen_Wrapper
    1 point
×
×
  • Create New...