Lord Vectronx Posted March 14, 2014 Share Posted March 14, 2014 (edited) Hello, I'm a lazy boy (it's a shame I know ) and I would like to avoid rewriting an existence test whenever I need it, so I created a configurable module that replaces invented a code for Used by expressions Autoit. Here is the code in question: Func ISITALIVE($txt) $txt = StringReplace($txt, "IN", "If Not ") $txt = StringReplace($txt, "OWE", " Or WinExists") $txt = StringReplace($txt, "IPE", "If ProcessExists") $txt = StringReplace($txt, "IWE", "If WinExists") $txt = StringReplace($txt, "WE", "WinExists") $txt = StringReplace($txt, "PE", "ProcessExists") $txt = StringReplace($txt, "AN", " And Not ") $txt = StringReplace($txt, " A ", " And ") $true = 1 While $true = 1 $result = Execute($txt) If $result = 1 Then $true = 0 EndIf Sleep(180000) WEnd MsgBox(0,"All Processes Ended?","Indeed!") EndFunc ;==>ISITALIVE ISITALIVE('INWE("Oracle Universal Installer")ANPE("oui.exe")ANPE("java.exe")OWE("Notepad")') The goal here: wait until one or more processes end and verify all 180s that is the case, if yes, then continue Problem: The expression gives what is expected, $txt = 'If Not WinExists ("Oracle Universal stallert") And Not ProcessExists ("oui.exe") And Not ProcessExists ("java.exe") Or WinExists ("Notepad")' However, when I run $txt, So Execute($txt) , the variable $result should be 1 or 0, but there is nothing. That does not work either with Eval () Question: How to "run" the contents of a variable containing Autoit controls (or commands)? Thank you in advance for your answers Edited March 14, 2014 by Lord Vectronx Link to comment Share on other sites More sharing options...
l3ill Posted March 14, 2014 Share Posted March 14, 2014 Make a Func out of it and call it from your existing Function Or make a script, compile it and Execute it when needed. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
water Posted March 14, 2014 Share Posted March 14, 2014 Why not add your abbreviations to the SciTE abbr. list? When you type "OWE" plus space SciTE expands it to " Or WinExists"). My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jdelaney Posted March 14, 2014 Share Posted March 14, 2014 (edited) You'll probably need to break down the calls, and run them as a 'call'...such as: $result = Call("WinExists","Oracle Universal Installer") Use some good'ol regexp for that. This will break out all the qualifiers, and parameters (currently, only up to 4, but you can add in more) into an array of arrays...you would then need to logically cunstruct the 'Call', based on the current array: Func ISITALIVE($txt) $txt = StringReplace($txt, "IN", "If Not ") $txt = StringReplace($txt, "OWE", " Or WinExists") $txt = StringReplace($txt, "IPE", "If ProcessExists") $txt = StringReplace($txt, "IWE", "If WinExists") $txt = StringReplace($txt, "WE", "WinExists") $txt = StringReplace($txt, "PE", "ProcessExists") $txt = StringReplace($txt, "AN", " And Not ") $txt = StringReplace($txt, " A ", " And ") $true = 1 ConsoleWrite($txt & @CRLF) $a = StringRegExp($txt,"(\w+\s)?(\w+\s)?(\w+\s?)\(([^\),]+)?,?([^\),]+)?,?([^\),]+)?,?([^\),]+)?\)",4) For $i = 0 To UBound($a) -1 _ArrayDisplay($a[$i]) Next EndFunc ;==>ISITALIVE ISITALIVE('INWE("Oracle Universal Installer","test2")ANPE("oui.exe")ANPE("java.exe")OWE("Notepad")') Edited March 14, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Lord Vectronx Posted March 14, 2014 Author Share Posted March 14, 2014 (edited) Thanks for all your advices, I do not know if I've done well understood, but the goal is not simply to replace the formulas in the given arguments, but to interpret the command (such as a Java runtime). It keeps me from typing too much on the one hand, and to perform dynamic tests at the discretion of future developments (from a response file for example), all in a script as simple as possible @l3ill Make a function that is already my goal, either by #include or by simply copying and pasting in every script where I need it, the final idea for example to read directly coded lines (OWE etc. .. ) via a response file @Water I'm not familiar with editing configuration files supplied with AutoiT/Scite, the last time I crashed and I had to reinstall, but it's an idea, I'll have a look. Your idea seems to me the most accessible .. remains to be seen if I change the right section ... Question: files modified configurations, are they crushed in the next update (of AutoIt or Scite4Autoit) or should I think about save them before? @jdelaney Thank you for your snippet, I'll test it and let you know I've never used this command, but it seems a little difficult for such a trivial code .. I'm a lazy man you remember but I do not begrudge the effort if necessary although I see the result provided by your script, I do not see how that all commands are interpreted at the same time. IF NOT XXX IF XXX and (IF NOT XXX) or (IF XXX) will be interpreted differently, or maybe I'm wrong I tried to use your idea to push further the concept, here is the modified code: Func SWAPIT($txt) $txt = StringReplace($txt, "INWE", "If Not WinExists") $txt = StringReplace($txt, "OWE", " Or WinExists") $txt = StringReplace($txt, "IPE", "If ProcessExists") $txt = StringReplace($txt, "IWE", "If WinExists") $txt = StringReplace($txt, "WE", "WinExists") $txt = StringReplace($txt, "PE", "ProcessExists") $txt = StringReplace($txt, "AN", " And Not ") $txt = StringReplace($txt, " A ", " And ") Return $txt EndFunc ;==>SWAPIT Func ISITALIVE($txt) $b = StringSplit($txt, "!") $d = "" For $c = 1 To $b[0] ConsoleWrite($txt & @CRLF & "NB=" & StringInStr($b[$c], "(") - 1 & @CRLF & $b[$c]) $result = SWAPIT($b[$c]) $a = StringRegExp($result, "(\w+\s)?(\w+\s)?(\w+\s?)\(([^\),]+)?,?([^\),]+)?,?([^\),]+)?,?([^\),]+)?\)", StringInStr($b[$c], "(") - 1) MsgBox(0, "CodedExp=" & $b[$c] & @CRLF & "Result after swap=" & $result) For $i = 0 To UBound($a) - 1 _ArrayDisplay($a[$i]) $d = $d + $a[$i] Next MsgBox(0, "Final Expression is: " & $d) Next EndFunc ;==>ISITALIVE ISITALIVE('INWE("Oracle Universal Installer","test2")ANPE("oui.exe")ANPE("java.exe")OWE("Notepad")') But still not performing to, my problem remains the same: how to run the final expression obtained? Any idea ?? Edited March 14, 2014 by Lord Vectronx Link to comment Share on other sites More sharing options...
jdelaney Posted March 14, 2014 Share Posted March 14, 2014 (edited) What my example does, is break up all the data into arrays, which you can then logically dump into the Call function. You would need switch statements/logic to determine the different options necessary. If you put the subscripts back into a string, then you defeat the purpose Something like this (I haven't fully debugged it) Logically, the first array determines if the condition is met OR, if there is an OR statement, start here again. Logically, if there is an AND statement, and the prior array did NOT match it's expected result (which is determined by the NOT or lack there of), then it continues until an OR statement occurs...in which case this line starts freshly from step 1). Logically, if there is an AND statement, and the prior array DID match, then it checks if the current statement matches (like above), and continues If ALL statements in the AND groups are met, and an OR statement occurs, then the loop exits, and function ends. expandcollapse popup#include <Array.au3> Func ISITALIVE($txt) $txt = StringReplace($txt, "IN", "If Not ",0,True) $txt = StringReplace($txt, "OWE", " Or WinExists",0,True) $txt = StringReplace($txt, "IPE", "If ProcessExists",0,True) $txt = StringReplace($txt, "IWE", "If WinExists",0,True) $txt = StringReplace($txt, "WE", "WinExists",0,True) $txt = StringReplace($txt, "PE", "ProcessExists",0,True) $txt = StringReplace($txt, "AN", " And Not ",0,True) $txt = StringReplace($txt, " A ", " And ",0,True) $true = 1 ConsoleWrite($txt & @CRLF) $a = StringRegExp($txt,"(?i)(?:If)?(\w+\s)?(\w+\s)?(\w+\s?)\(([^\),]+)?,?([^\),]+)?,?([^\),]+)?,?([^\),]+)?\)",4) $bMetCriteria = True For $i = 0 To UBound($a) -1 $aTemp = $a[$i] $bCondition = True For $j = 1 To UBound($aTemp)-1 If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "If" Then ContinueLoop If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "And" Then If Not $bMetCriteria Then ExitLoop Else ContinueLoop EndIf EndIf If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "" Then ContinueLoop If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "Or" Then If $bMetCriteria Then ExitLoop 2 $bMetCriteria = True ContinueLoop EndIf If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "Not" Then $bCondition = False ContinueLoop EndIf $bReturn = Call($aTemp[$j],$aTemp[$j+1]) ConsoleWrite($bCondition & @TAB & $bReturn & @TAB & $aTemp[$j] & @TAB & $aTemp[$j+1] & @TAB) ;~ _ArrayDisplay($aTemp) $bMetCriteria = ($bReturn = $bCondition) ExitLoop Next ConsoleWrite("Final:" & $bMetCriteria & @CRLF) Next Return $bMetCriteria EndFunc ;==>ISITALIVE $b = ISITALIVE('INWE("Notepad")ANPE("oui.exe")ANPE("java.exe")OWE("Notepad")') ConsoleWrite($b & @CRLF) Edited March 15, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Solution jdelaney Posted March 15, 2014 Solution Share Posted March 15, 2014 (edited) You can then get really tricky with my above, and output the remaining subscripts to an array (check helpfile with how to construct the array for the Call function). That way, if your function has multiple parameters, the Call will consider them all. As is, only the first param will be passed into the Call function...which is fine for the example you provided. Ouch, just noticed this in helpfile: The function cannot be a built-in AutoIt function or plug-in function. You'll have to create your own function that wraps the built in functions....like this: expandcollapse popup#include <Array.au3> Func ISITALIVE($txt) $txt = StringReplace($txt, "IN", "If Not ",0,True) $txt = StringReplace($txt, "OWE", " Or CallWinExists",0,True) $txt = StringReplace($txt, "IPE", "If CallProcessExists",0,True) $txt = StringReplace($txt, "IWE", "If CallWinExists",0,True) $txt = StringReplace($txt, "WE", "CallWinExists",0,True) $txt = StringReplace($txt, "PE", "CallProcessExists",0,True) $txt = StringReplace($txt, "AN", " And Not ",0,True) $txt = StringReplace($txt, " A ", " And ",0,True) $true = 1 ConsoleWrite($txt & @CRLF) $a = StringRegExp($txt,"(?i)(?:If)?(\w+\s)?(\w+\s)?(\w+\s?)\(([^\),]+)?,?([^\),]+)?,?([^\),]+)?,?([^\),]+)?\)",4) $bMetCriteria = True For $i = 0 To UBound($a) -1 $aTemp = $a[$i] $bCondition = True For $j = 1 To UBound($aTemp)-1 If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "If" Then ContinueLoop If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "And" Then If Not $bMetCriteria Then ExitLoop Else ContinueLoop EndIf EndIf If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "" Then ContinueLoop If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "Or" Then If $bMetCriteria Then ExitLoop 2 $bMetCriteria = True ContinueLoop EndIf If StringRegExpReplace($aTemp[$j],"[\s\r\n]","") = "Not" Then $bCondition = False ContinueLoop EndIf $bReturn = Call($aTemp[$j],StringRegExpReplace($aTemp[$j+1],'["]',"")) ConsoleWrite($bCondition & @TAB & $bReturn & @TAB & $aTemp[$j] & @TAB & $aTemp[$j+1] & @TAB) ;~ _ArrayDisplay($aTemp) $bMetCriteria = ($bReturn = $bCondition) ExitLoop Next ConsoleWrite("Final:" & $bMetCriteria & @CRLF) Next Return $bMetCriteria EndFunc ;==>ISITALIVE $b = ISITALIVE('IWE("[CLASS:Notepad]")ANPE("oui.exe")ANPE("java.exe")OWE("[CLASS:Notepad]")') ConsoleWrite($b & @CRLF) Func CallWinExists ($sWindow) Return WinExists($sWindow) EndFunc Func CallProcessExists ($sProcess) Return ProcessExists($sProcess) EndFunc Edit: I love this kind of crap Edited March 15, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Lord Vectronx Posted March 17, 2014 Author Share Posted March 17, 2014 Wow, fantastic mister Jd, bravo ... high-level programming! I have not understand everything but I'm working on it because I've never used the function call, and I confess that I am a bit overwhelmed (question time , I work on a lot of things right now). Anyway thank you for everything. If I'm stuck on something I hope not to abuse by asking for help again Edit: I love this kind of crap Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now