Eggie6 Posted June 21, 2015 Posted June 21, 2015 Hi,i have this scriptexpandcollapse popupFor $iii=1 To _FileCountLines("stat.txt") $sLine = FileReadLine("stat.txt",$iii) $GAhti = $iii - 3 $GAati = $iii + 3 $BPhti = $iii - 3 $BPati = $iii + 3 $SOGhti = $iii - 3 $SOGati = $iii + 3 $SOThti = $iii - 3 $SOTati = $iii + 3 $BShti = $iii - 3 $BSati = $iii + 3 If StringInStr($sLine,"Goal Attempts") <> 0 Then $GAht = FileReadLine("stat.txt",$GAhti) $GAat = FileReadLine("stat.txt",$GAati) EndIf If StringInStr($sLine,"Ball Possession") <> 0 Then $BPht = FileReadLine("stat.txt",$BPhti) $BPat = FileReadLine("stat.txt",$BPati) EndIf If StringInStr($sLine,"Shots on Goal") <> 0 Then $SOGht = FileReadLine("stat.txt",$SOGhti) $SOGat = FileReadLine("stat.txt",$SOGati) EndIf If StringInStr($sLine,"Shots off Goal") <> 0 Then $SOTht = FileReadLine("stat.txt",$SOThti) $SOTat = FileReadLine("stat.txt",$SOTati) EndIf If StringInStr($sLine,"Blocked Shots") <> 0 Then $BSht = FileReadLine("stat.txt",$BShti) $BSat = FileReadLine("stat.txt",$BSati) EndIf If $BPht <> "" Then MsgBox(1,"", "Ball possession HT" & ': ' & $BPht & @LF & "Goal attempts HT" & ': ' & $GAht & @LF & "Shots on Goal HT" & ': ' & $SOGht & @LF) EndIf MsgBox(1,"",$GAht) MsgBox(1,"",$SOGht) $GAht = "" $GAat = "" $BPht = "" $BPat = "" $SOGht = "" $SOGat = "" $SOTht = "" $SOTat = "" $BSht = "" $BSat = "" Next ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- EndIf _IEQuit($aaaa) Nextin this way, msgbox returns literally empty x times .... if i remove those lower 2 msgboxes, msgbox returns only the string that's in IF ....which means If $BPht <> "" Thenreturns only $BPht value in msgbox,If $GAht <> "" Thenreturns only $GAht in msbox,Could you please help me with it?
JohnOne Posted June 21, 2015 Posted June 21, 2015 You will receive better help with a stat.txt sample. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Eggie6 Posted June 21, 2015 Author Posted June 21, 2015 Match1st Half2nd Half 49% Ball Possession 51% 13 Goal Attempts 14 3 Shots on Goal 3 3 Shots off Goal 4 7 Blocked Shots 7 9 Free Kicks 17 1 Corner Kicks 7 7 Offsides 0 18
mikell Posted June 21, 2015 Posted June 21, 2015 (edited) You should first remove empty lines, then read the text to an array and loop through this array#include <Array.au3> $txt = StringRegExpReplace(FileRead("stats.txt"), '(?m)^\s*\R', "") ;Msgbox(0,"", $txt) ; for preview $array = StringSplit($txt, @crlf, 1) ;_ArrayDisplay($array) ; for preview Local $goalattempts ; example For $i = 1 to $array[0] If StringInStr($array[$i], "Goal Attempts") Then $goalattempts &= $array[$i-1] Next Msgbox(0,"", "goal attempts : " & $goalattempts)EditBTW can't _IE* funcs give you a better result than this file ? Edited June 21, 2015 by mikell
Eggie6 Posted June 21, 2015 Author Posted June 21, 2015 (edited) You should first remove empty lines, then read the text to an array and loop through this array#include <Array.au3> $txt = StringRegExpReplace(FileRead("stats.txt"), '(?m)^\s*\R', "") ;Msgbox(0,"", $txt) ; for preview $array = StringSplit($txt, @crlf, 1) ;_ArrayDisplay($array) ; for preview Local $goalattempts ; example For $i = 1 to $array[0] If StringInStr($array[$i], "Goal Attempts") Then $goalattempts &= $array[$i-1] Next Msgbox(0,"", "goal attempts : " & $goalattempts)EditBTW can't _IE* funcs give you a better result than this file ?and i've got same outcome... ; find the line that has the search string $txt = StringRegExpReplace(FileRead("stat.txt"), '\s{2,}', @crlf) ;Msgbox(0,"", $txt) ; for preview $array = StringSplit($txt, @crlf, 1) ;_ArrayDisplay($array) ; for preview $goalattempts="" $BallPossession="" $ShotsonGoal="" $ShotsoffGoal="" For $p = 1 to $array[0] If StringInStr($array[$p], "Goal Attempts") Then $goalattempts = $array[$p-1] Else EndIf If StringInStr($array[$p], "Ball Possession") Then $BallPossession = $array[$p-1] Else EndIf If StringInStr($array[$p], "Shots on Goal") Then $ShotsonGoal = $array[$p-1] Else EndIf If StringInStr($array[$p], "Shots off Goal") Then $ShotsoffGoal = $array[$p-1] Else EndIf If $BallPossession <> "" Then MsgBox(1,"", "Ball possession HT" & ': ' & $BallPossession & @LF & "Goal attempts HT" & ': ' & $goalattempts & @LF & "Shots on Goal HT" & ': ' & $ShotsonGoal & @LF) EndIf Next nvm, i just had to put msgbox outside of loop... :S Edited June 21, 2015 by Eggie6
mikell Posted June 22, 2015 Posted June 22, 2015 Anyway for better efficiency may I suggest this way#include <Array.au3> $txt = StringRegExpReplace(FileRead("stats.txt"), '(?m)^\s*\R', "") $array = StringSplit($txt, @crlf, 1) Local $Items[8] = ["Ball Possession", "Goal Attempts", "Shots on Goal", "Shots off Goal", "Blocked Shots", "Free Kicks", "Corner Kicks", "Offsides"] _ArrayColInsert($Items, 1) _ArrayColInsert($Items, 2) For $i = 1 to $array[0] For $j = 0 to UBound($Items)-1 If StringInStr($array[$i], $Items[$j][0]) Then $Items[$j][1] = $array[$i-1] $Items[$j][2] = $array[$i+1] EndIf Next Next _ArrayDisplay($Items)
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