KANlFUSA Posted August 22, 2015 Share Posted August 22, 2015 (edited) any idea to make an autoit script auto total the numbers inside notepad file and show the result in msgbox?like' 133+34+55+41+639.3 = msgbox the total amount. below is notepad user.txt-------------------------------------------------------[user]133345541639.3 Input=0-------------------------------------------------------- Edited August 31, 2015 by KANlFUSA Link to comment Share on other sites More sharing options...
Danyfirex Posted August 22, 2015 Share Posted August 22, 2015 (edited) it is not the best way but should work.#include <Array.au3> Local $sData=fileread("user.txt") $sData=StringMid($sData,1,StringInStr($sData,"Input")) ;just for avoid last number (0) no needed if is 0 Local $aData=StringRegExp($sData,"[-+]?[0-9]*\.?[0-9]+",3) ;~ _ArrayDisplay($aData) array result of numbers Local $sResult="" For $i= 0 to UBound($aData)-1 $sResult&= (($i <> 0) ? "+" : "") & $aData[$i] Next MsgBox(0,"",$sResult & " = " & Execute($sResult))Saludos Edited August 22, 2015 by Danyfirex KANlFUSA 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
CrypticKiwi Posted August 22, 2015 Share Posted August 22, 2015 (edited) here is another way without using regex...you decide which is better for you$Handle = FileOpen("user.txt",0) $Read = FileRead($Handle) $Counter = 0 $Sum = 0 $Exit = True $Readline = "" while $Exit $Counter += 1 $ReadLine = FileReadLine("user.txt",$Counter) if @error <> 0 Then $Exit = False EndIf $Sum += $ReadLine WEnd MsgBox("","",$Sum) Edited August 22, 2015 by CrypticKiwi Edit for a better way to detect end of File KANlFUSA 1 Link to comment Share on other sites More sharing options...
KANlFUSA Posted August 22, 2015 Author Share Posted August 22, 2015 Thank you Danyfirex&Thank you CrypticKiwi Link to comment Share on other sites More sharing options...
iamtheky Posted August 22, 2015 Share Posted August 22, 2015 probably edge cases aplenty, but shorter:#include <Array.au3> Local $sData=FileRead("user.txt") Local $aData = StringRegExp($sData , "\n(\d+\.*\d*)" , 3) msgbox(0, '' , execute(_ArrayToString($aData , "+"))) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Malkey Posted August 23, 2015 Share Posted August 23, 2015 Length really doesn't matter. But, just in case there's this one.MsgBox(0, 'Results', Execute(StringRegExpReplace(FileRead("user.txt"), "\D*(\d+\.?\d*)\R*", "\1+") & 0)) Link to comment Share on other sites More sharing options...
jchd Posted August 23, 2015 Share Posted August 23, 2015 This is much better in that it adds the first line and allows for various line terminations, but we might as well allow signed values:MsgBox(0, 'Results', Execute(StringRegExpReplace($sData, "([+-]?\d+\.?\d*)\R*", "\1+") & '0')) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Gianni Posted August 23, 2015 Share Posted August 23, 2015 @kanifusa if you want read the numbers directly from the running notepad rather than from a file you can use this snippetif WinExists("[CLASS:Notepad]", "") then $sData = WinGetText(WinGetHandle("[CLASS:Notepad]", "")) MsgBox(0, 'Results', Execute(StringRegExpReplace($sData, "([+-]?\d+\.?\d*)\R*", "\1+") & '0')) ; <- this by jchd Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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