d0n Posted April 17, 2007 Posted April 17, 2007 What i wanted to do is to read from a txt file that is constantly being updated the file will contain stuff like: AAA is 999 BCA is 513 AAA is 511 and so on what i want to do is add all the ones with the same name (ex. AAA) how would i go about reading mass info and collecting it to show if possible in realtime or if not just in the end? Thanks for your help
Thatsgreat2345 Posted April 17, 2007 Posted April 17, 2007 Here is a message from God $sString = "AAA is 999" & @CRLF & "BCA is 513" & @CRLF & "AAA is 511" $aArray = StringRegExp($sString, '(?s)(?i)AAA is (\d+)', 3) If IsArray($aArray) Then $nAdd = '' For $iCC = 0 To UBound($aArray) - 1 $nAdd += $aArray[$iCC] Next MsgBox(64, 'Info', 'Total of AAA = ' & $nAdd) EndIf
d0n Posted April 17, 2007 Author Posted April 17, 2007 could you maybe explain to me what you are doing here????? and is this able to read a .txt file that is being constantly updated?? Thanks
SadBunny Posted April 17, 2007 Posted April 17, 2007 d0n said: could you maybe explain to me what you are doing here?????and is this able to read a .txt file that is being constantly updated??ThanksHe creates a string that contains exactly what you would read from the file in your example, so he doesn't have to actually create a testfile. Imagine a file containing that example, read it with FileRead() and you will end up with a string just like that. Seems like what you would want.Then he uses stringRegExp to create an array with all the AAA numbers (in this case).Then he loops through the array, and has a result variable to which each number behind an AAA is added.In the end he shows the variable.'being constantly updated' might pose some trouble though depending on what you mean exactly... If the file is constantly in use (opened) by another program, you will not even be able to access it because of sharing violation problems, but if you mean that data will be written to it periodically but that you need to skip the parts that you have already read, you can try FileReadLine. (You can keep track of the amount of lines read, and tell the FileReadLine to get the line numbers you haven't yet read.) For this, minor tweaking of the for/next loop and possibly the stringRegExp command is in order. Roses are FF0000, violets are 0000FF... All my base are belong to you.
d0n Posted April 17, 2007 Author Posted April 17, 2007 the .txt is constantly being updated by another program (Logging what happens in the program) but everytime you reopen it new info will be out hope that helps that part as for the numbers and names part i think i kinda get it :S but i'll have to try it myself when i get back tonight Thanks for all your help so far!
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