Jump to content

SadBunny

Active Members
  • Posts

    1,444
  • Joined

  • Last visited

  • Days Won

    8

SadBunny last won the day on December 28 2016

SadBunny had the most liked content!

About SadBunny

  • Birthday 01/01/1979

Profile Information

  • Member Title
    Excusionist extraordinaire
  • Location
    Amsterdam, The Netherlands

Recent Profile Visitors

729 profile views

SadBunny's Achievements

  1. Note that the math here could get ambiguous. Say you want to know whether 98.01 and 100 are "equal" within a 2% range. Well, 98.01 is 98.01% of 100, so yes, But 100 is 1,0203% of 98, so more than 2% away, so no. In other words, keep the order of the numbers in mind using this logic.
  2. Sure... Something like this: Global $aArray[5] = ["abc", "def", "ghi", "", "mno"] MsgBox(64, "first empty index", getFirstEmptyIndex($aArray)) Func getFirstEmptyIndex($ar) For $index = 0 to UBound($ar) - 1 If $ar[$index] = "" Then Return $index Next Return -1 EndFunc ;==>getFirstEmptyIndex Note that it will return a 3 as arrays are 0-based, instead of the 4 you expected. If you need it to return 4, you can easily fix that in this snippet.
  3. How about breaking things up into nice separate functions so your program flow is much easier to control/steer? Something like this (with a lot of pseudocode that you can fill in yourself ): Global $MAX_PWD_FAIL_COUNT = 3 ; main script If Not fireItUp() Then MsgBox(16, "error", "something went wrong, you probably got an earlier error about this") Else MsgBox(64, "all good", "vpn logged in!") EndIf Exit Func fireItUp() $clientGui = startClient() If Not $clientGui Then MsgBox(64, "failure to start client", "failed") Return False EndIf $failCount = 0 While Not loginClient($clientGui) $failCount += 1 If $failCount > $MAX_PWD_FAIL_COUNT Then MsgBox(16, "failure to login client", "failed " & $MAX_PWD_FAIL_COUNT & " times! Cancelling.") ; break down gui, kill process, whatever cleanupAfterFailedLogin() ; Return False, so the calling code can tell that stuff went wrong Return False EndIf WEnd ; If we get here, we know that everything was ok cleanupAfterCorrectLogin() Return True ; EndFunc ;==>fireItUp Func startClient() ; Start client ; Return $hVPN1 if success, False if failure EndFunc ;==>startClient Func loginClient($clientGui) ; Do login stuff using $clientGui ; Wait for window to reflect success (then return True) or failure (then return False) EndFunc ;==>loginClient Func cleanupAfterCorrectLogin() cleanupGeneral() ; ini write, log write, whatever specific for handling correct login EndFunc ;==>cleanupAfterCorrectLogin Func cleanupAfterFailedLogin() cleanupGeneral() ; ini write, log write, whatever specific for handling failed login EndFunc ;==>cleanupAfterFailedLogin Func cleanupGeneral() ; gui process/windows close, ini write etc., anything that needs to be done whether everything worked or not EndFunc ;==>cleanupGeneral
  4. Sure... Use the IE.au3 UDF to work on websites. (See "IE Management" in the helpfile and all the example scripts of all the functions that start with _IE.)
  5. Too late. You have already offended me, insulted my intelligence and disrespected my constitutional freedoms. It is the worst thing that ever happened to me and I am already on the phone with Dr. Phil's production team.
  6. Very true. I missed that as I copypasted it from the original question Edited.
  7. Well, as per that snippet, the script will exit if you press Yes and if you press No. Your initial oneliner solution works, but you just have to change that digit to the correct one (i.e. 6). If MsgBox(68, "Test", "Do you want to exit?") = 6 Then Exit MsgBox(64, "test", "You pressed no!")
  8. This script has so many problems, I don't know where to start. Try reading some example scripts and searching for all the errors you get running this script, so you can at least either provide a version without the syntax errors, or ask about the specific errors you don't know how to fix. Also, this is a strangely specific to want to automate. What application are you automating? There is probably a much better way to accomplish what you are trying to do.
  9. Well, the best website of the entire interwebz (except for this forum of course ) is this: https://regex101.com It is awesome for building and testing regular expressions and very nicely featured. There are some other sites but as far as I have seen nothing even comes close... Check this out (not mine, but from the publicly available library): https://regex101.com/r/mIA28O/1 You gotta love that sh*t! And it's free (well, you can donate but it is very modest about it) and you can save and publicize your regex work and use multiple flavors... It's just awesome.
  10. Well, to be honest I stole it from this famous stackoverflow answer about parsing HTML with Regex. It is beautiful. It is well-put. It is immediately clear. It leaves no questions and it takes no prisoners. All my base are belong to it /edit: Actually I didn't steal the font but the idea I had this page handle the characters for me.
  11. No problem Watch out though - rege̢x҉ has a tend̕e͡nçy to drive yo u͝ ą̀͟bsò̡͘lu̶ţ̡ ely s̀̕͢t̴̀̕a̷͠r͢͞k̕͜͝ r̨͘a̵v͠͏i̵ǹ̵g̸̶ bonkers a̵̴ǹ͞͏d̸͞ is al̡҉͝ş̛̕o̴̡ ̷̧͘ex͏̶҉t͟͞ré̢mé̢l̀͏͢y̧҉͟ ̵a̶̴̴d̸̛ḑ͞i͏ç̡̢t̵͠ìv͜e̸̸͡ . It pushes i͜ts̕el̀f ̨on you̕ like a hellish s͢͢͞͠͠c̵̛̕̕o͡͠u̶̢̕r͏̷̢͘ģ̴̴͠͠e͜͟ ̴̧͞͝͞o̸̕͝͏f̡͏̸͡ ͟e̷̵̡̡͜v̸͟͜͞i͏̨͟l̨͢ an d̴̕҉ ̕ma҉̕͡ke͞s͢ ̡i͠t̶̨se͟l̡f͝ ̀s͞͝͡ęe҉̀̕m͞ ͞li̵͡k͡e ̛́t̵̢h̸e͜ ̵́̕ only hammer you will ever need to solve any problem! Damn you regex, daaaaamn you alllll to hellllllll W̷̡̡̪̤͕͉͙͎̳͋̎̓͑͐̑ͤ͆̎͊͟͠H̷̴̡̟̠͙͎͚̪͇̭̻̲̻͔͛̋ͧͣ͆̉͑̽́͌̄̓ͪ͘Y̵̴̗̘͚̞̦͈̮͈͚͈̖̍̔̂̇͡͞ͅ ̵̵̡̧͕̞͈̝̫͎̖̩͕̻͓̜̣̝͚͓̠̺͑ͬͮ͌̋ͮͪ̂ͧͫ͊ͤ̽͂͆̃͞R̒ͩ̂ͧ̊͒̿͛̿̽ͪ̿ͤ̒̐͒ͭͩͣ͜҉̸̘͓̭̗͙̯̠̼ͅĒ̢̫̜̘̱̠͇͕̘̦͔͖͎̫̻̦̂̅ͪ̃͛̕G̨̰͍̫̮̠̼͔̭͎̃ͬ̂̎ͦ͂ͦ̋ͯͩ̉̌̆̑̊̃̃͢͡E̥̣̺̜̹̞̲̗͖̮̗͊ͥ͌ͧͮ̂͋͑̈ͧͯ̃̾ͯ͘͞͞X̶̡̿͋͂ͧ̊̎ͨͬ͆̒͑̓̌͗̍̚͞͞͏̙̭͎͉͎̼̭ ̂̃̊͏͇̦̠͇̭͇̬̳̠̗̪̱̣͚̞̳̗́Ẇ̴̵̞̳̻̼̟͚̤̪̊̍̈̊̓ͧ̒̐̈́̇̕ͅH̷̥̹̼͙̮̮̻̯͉̹̞̰̙ͬͦͯ̑ͪͨ̌̽ͯ̍̉̓̈́̆͊̈̃̚͞͠͠Ÿ̢̞̘͖̼̰̠͉̞̻̙̯́͊ͭ͗̔̒͑̃̾͛ͦͅ
  12. Well, almost The dot is a "wildcard" that stands for any character, but only exactly ONE instance of any character (read: not zero, not more than one, but exactly one). In regex, you can consider it a character class. So, .* literally means "exactly ONE character, and that zero or more times", which ends up being "zero or more of any character". Yes, \s* means "a string of zero or more whitespace characters". It doesn't matter which whitespace characters or in which order they are. ({space} matches, {space}{space}{space}{tab}{tab}{space}{space}{tab}{space} also matches). Yes, your conclusion is correct, but it is important to always realize that the * means zero or more (whereas the + means one or more). So your "any quantity" can also be zero. Which is why my snippet had a testcase for "kk&kk".
  13. The asterisk in regex is unlike the asterisk in for example a regular filespec, with which you are probably confusing it. In a filespec it just means "zero or more characters". (auto*.bat matches auto.bat, autoexec.bat auto_hello.bat etc.) Instead, in regex, it refers to the thing (the "token") that precedes it, and matches "zero or more repetitions of the preceding token". That token can be a character set (like in this case the set in character class \s, or something like [:alnum:] ), but it could also be a character set like [a-g] or a capturing group like (red|green|blue) (the pipe means OR). Note: the + means almost the same thing, but then "one or more repetitions of the preceding token". Note: there is another gotcha (well, many others, regex can be tricky sometimes ) in the difference between filespecs and regex patterns: the period (.) . In regex it means "any character". So putting all that together, if you take auto*.bat as your regex pattern, it would mean: Literal "aut", followed by zero or more occurrences of literal "o", followed by any character, followed by literal "bat". So it would match things you may not expect it to match thinking from a used-to-filespecs perspective, like: autoXbat autoooooooooooooooXbat autXbat (<-- note: zero occurrences of the "o" !) autobat (<-- read: zero occurrences of the "o", followed by one character before "bat" which matches the dot, and happens to be a literal "o") ... but "autbat" would not match, as there is no character in there to match the period (which requires one character) between "aut" and "bat". Note that regular expressions have nothing to do with files or filespecs. Last note: to specify what you originally thought * did, namely "zero or more characters", in regex you would use ".*", which would mean: zero or more repetitions of <any character>. So: abc.*xyz would be matched by "abcxyz", "abc123xyz", "abc {tab} I see dead people my preciousssssss xyz". Read (lots) more on: http://www.regular-expressions.info/repeat.html for repetitions, and ofcourse the other pages on www.regular-expressions.info or one of the other myriads of online resources. Hope this cleared it up a bit (but I have a tendency to complicate matters if I start explaining stuff - if so then sorry )
  14. Is this what you mean? ConsoleWrite(doThingy("kk&kk") & @CRLF) ConsoleWrite(doThingy("kk& kk") & @CRLF) ConsoleWrite(doThingy("kk &kk") & @CRLF) ConsoleWrite(doThingy("kk & kk") & @CRLF) ConsoleWrite(doThingy("kk & kk") & @CRLF) ConsoleWrite(doThingy(" & foo &bar &foobar& bar& foo") & @CRLF) Func doThingy($s) Return StringRegExpReplace($s, "\s*&\s*", " & ") EndFunc ;==>doThingy Output: kk & kk kk & kk kk & kk kk & kk kk & kk & foo & bar & foobar & bar & foo
  15. You can check the color of pixels at specific coordinates ( PixelGetColor() ) and perform a mouse click on specific coordinates ( MouseClick() ). Check the help file, they have example scripts. So you could write a script in a loop waiting for color changes to occur at specific coordinates, then react to those changes. It sounds like that would probably get you to a very basic version of what you're looking for. Then again, it's hard to tell exactly because you're being vague about your applications. Could you maybe post a couple of screenshots (block out any specific company information if you need to) so we have an idea what you're dealing with? Also, maybe it's an option to go back to the people who wrote that proprietary software for you and ask them for an improved interface or maybe discuss with them some automatic actions you may want to configure, so you don't have to script it yourself?
×
×
  • Create New...