Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/28/2016 in all areas

  1. Do you mean something like this: Local $s = "<li>One<li>Inner<li>Innermost</li></li></li><li>Two</li>" Local $regex = _ '(?imsx)' & _ '(?(DEFINE) (?<LiStart> <li> ) )' & _ '(?(DEFINE) (?<LiEnd> <\/li> ) )' & _ '(?(DEFINE) (?<LiBlock> (?&LiStart) (?: (?&LiBlock)* | .*? )* (?&LiEnd) ) )' & _ '(?&LiBlock)' $data = StringRegExp($s, $regex, 3) _ArrayDisplay($data) Note that this seemingly complex regexp is using an explicitely recursive pattern. Using named sub-patterns makes it more verbose but much clearer. The X (eXtended) option, allowing unescaped whitespaces to be unsignificant, also adds to readability. Refer to https://regex101.com/ for an english translation of the regexp semantics and debugging possibility. Also read up the official PCRE documentation for details on available constructs.
    3 points
  2. Excellent suggestion. Why didn't I think at that myself? I'll add the code.
    2 points
  3. There are actually quite some problems in your retry() function: You call the _FindHero() function from within the MsgBox, which makes it just display the return value of the _FindHero in the "success" MsgBox, even if it failed. Solution: assign the value of the _FindHero($html) call to a variable, then decide between success and failure based on that value. The retry() function calls itself. That is called recursion, and you should not use it in this way because if a function calls itself too many times the script will break. In fact, I'd say don't use it at all before you understand what the power is and what the potential problems are. Your retry() function loops through the same array as your _FindHero() function. While that is not technically an error, it's probably not what you meant. Also, your $html is read in the beginning of the script, and never again. You seem to be waiting for an update on that localhost site, which means that you must re-read that site every time you want to check for that update. No way to actually test your code without that localhost site and your herolist ini, but this should probably come a lot closer to what you want: #include <INet.au3> Global $aArray = IniReadSection(@ScriptDir & "\herolist.ini", "heros") Call("doMainLoop") Func _FindHero($sString) For $i = 1 To $aArray[0][0] If StringInStr($sString, $aArray[$i][1]) Then Return $aArray[$i][1] Next ; If we got here, the whole array was searched but nothing was found. ; If a hero was found, we will not get to this point because of the Return above. ; So, as a fallback return value, we will now: Return False ; <-- was Return "none" EndFunc ;==>_FindHero Func doMainLoop() ; <-- was "retry" While True ; <-- loop forever, or until we explicitly make it stop Local $html = _INetGetSource('http://localhost:1201') ; <-- re-read the site Local $foundHero = _FindHero($html) ; <-- store result value in variable ; note that $foundHero will now be set to False if no hero found If Not $foundHero Then Sleep(30000) ; <-- $foundHero was False, so we just wait 30 seconds ; ... and let the loop restart itself. No need to call ; the doMainLoop() function again! Else SoundPlay(@WindowsDir & "\media\tada.wav", 1) MsgBox(0, "Success", "The hero found was: " & $foundHero) Exit EndIf WEnd ; <-- loop restarts. EndFunc ;==>doMainLoop
    1 point
  4. Hi, ... about setting style of items: I see you can set style by setting the $iFontStyle in function calls as following: ; $iFontStyle - Text style of item or subitem ; Use the following values for $iFontStyle ; 0: Normal text style (default) ; 1: Bold text style ; 2: Italic text style ; 3: Underline text style ; These predefined constants can also be used: ; $iFontStyleNormal, $iFontStyleBold, $iFontStyleItalic, $iFontStyleUnderline ; If $sFontName is a font handle $iFontStyle is ignored If allowed I would propose this: Instead of using values 1 or 2 or 3 for bold or italic or underline respectively, It could be used 1, 2 , 4 (bit values) allowing in this way the use of more styles for a single item just summing values together, so, for example bold AND underline become 5 (that is 1 + 4) with a quick test, I've seen that it works by just changing this part in the UDF Switch $iFontStyle Case 0 ; Normal Case 1 ; Bold DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) ) Case 2 ; Italic DllStructSetData( $tLogFont, "Italic", True ) Case 3 ; Underline DllStructSetData( $tLogFont, "Underline", True ) Case Else If $sFontName Then DllStructSetData( $tLogFont, "FaceName", $sFaceName ) ; Reset $tLogFont on error Return SetError(5, 0, -1) ; Invalid font style EndSwitch with something like this for example: If BitAND($iFontStyle,1) Then DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) ) ; Bold If BitAND($iFontStyle,2) Then DllStructSetData( $tLogFont, "Italic", True ) ; Italic If BitAND($iFontStyle,4) Then DllStructSetData( $tLogFont, "Underline", True ) ; Underline if instead I have misunderstood how to use styles, then just forget all of what i've said above... Thanks
    1 point
×
×
  • Create New...