l3ill Posted November 17, 2013 Share Posted November 17, 2013 (edited) Hi All, Every day I get a text file with info about what I will need for the next day.This file is full of useful information surrounded by useless clutter. Additionally there is some math that has to be done to get drivers totals and then final totals for ordering.So I wrote this script... I am posting this because there a lot of useful tidbits for the newer coders to glean.Questions and constructive comments are welcome.cya,BillUpdate: 24.09.15 order_zip.7zDownload the zip to test...I needed to turn this:expandcollapse popupXXXXX XXXXXXXX 29.10.2013 08:03:31 DMS 1.3.4 ON XXXXXXX/XXXXXXXXXXX ROUTE LOAD REPORT DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: A - DRIVER A QTY QTY QTY QTY TRUCK REFERENCE DESCRIPTION SCHED LOADED DELVRD REMAIN COUNT VARIANCE P18X 5-GALLON WATER (MS) 14 P19X 5-GAL.FLUORIDE WATER (MS) 4 P20X 5-GALLON WATER 36 P24X 5-GAL. FLUORIDATED WATER 40 20C DEPOSIT CREDIT 24C DEPOSIT CREDIT TOTAL DELIVERY ORDERS: 45 TIME IN:__________ MILEAGE IN:_____________ TOTAL WEIGHT: 0,000 TOTAL WORK UNITS: 0,000 TIME OUT:__________ MILEAGE OUT:_____________ TOTAL TIME:__________ TOTAL MILES:_____________ DRIVER OUT:____________________ DRIVER IN:____________________ MANAGER OUT:____________________ MANAGER IN:____________________ TOTAL KEYS REQUIRED: 7 ====================== AS BW ML NH RI SH US XXXXX XXXXXXXX 29.10.2013 08:03:31 DMS 1.3.4 ON XXXXXXX/XXXXXXXXXXX ROUTE LOAD REPORT DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: B - DRIVER B QTY QTY QTY QTY TRUCK REFERENCE DESCRIPTION SCHED LOADED DELVRD REMAIN COUNT VARIANCE P18X 5-GALLON WATER (MS) 3 P19X 5-GAL.FLUORIDE WATER (MS) 10 P20X 5-GALLON WATER 35 P24X 5-GAL. FLUORIDATED WATER 29 20C DEPOSIT CREDIT 24C DEPOSIT CREDIT TOTAL DELIVERY ORDERS: 39 TIME IN:__________ MILEAGE IN:_____________ TOTAL WEIGHT: 0,000 TOTAL WORK UNITS: 0,000 TIME OUT:__________ MILEAGE OUT:_____________ TOTAL TIME:__________ TOTAL MILES:_____________ DRIVER OUT:____________________ DRIVER IN:____________________ MANAGER OUT:____________________ MANAGER IN:____________________ TOTAL KEYS REQUIRED: 6 ====================== AS BW NS RI SH US XXXXX XXXXXXXX 29.10.2013 08:03:31 DMS 1.3.4 ON XXXXXXX/XXXXXXXXXXX ROUTE LOAD REPORT DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: C - DRIVER C QTY QTY QTY QTY TRUCK REFERENCE DESCRIPTION SCHED LOADED DELVRD REMAIN COUNT VARIANCE P18X 5-GALLON WATER (MS) 13 P19X 5-GAL.FLUORIDE WATER (MS) 11 P20X 5-GALLON WATER 37 P24X 5-GAL. FLUORIDATED WATER 37 20C DEPOSIT CREDIT 24C DEPOSIT CREDIT TOTAL DELIVERY ORDERS: 49 TIME IN:__________ MILEAGE IN:_____________ TOTAL WEIGHT: 0,000 TOTAL WORK UNITS: 0,000 TIME OUT:__________ MILEAGE OUT:_____________ TOTAL TIME:__________ TOTAL MILES:_____________ DRIVER OUT:____________________ DRIVER IN:____________________ MANAGER OUT:____________________ MANAGER IN:____________________ TOTAL KEYS REQUIRED: 6 ====================== AS BW ML ri SH US XXXXX XXXXXXXX 29.10.2013 08:03:31 DMS 1.3.4 ON XXXXXXX/XXXXXXXXXXX ROUTE LOAD REPORT DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: H - DRIVER H QTY QTY QTY QTY TRUCK REFERENCE DESCRIPTION SCHED LOADED DELVRD REMAIN COUNT VARIANCE P18X 5-GALLON WATER (MS) 11 P19X 5-GAL.FLUORIDE WATER (MS) 16 P20X 5-GALLON WATER 28 P24X 5-GAL. FLUORIDATED WATER 17 20C DEPOSIT CREDIT 24C DEPOSIT CREDIT TOTAL DELIVERY ORDERS: 37 TIME IN:__________ MILEAGE IN:_____________ TOTAL WEIGHT: 0,000 TOTAL WORK UNITS: 0,000 TIME OUT:__________ MILEAGE OUT:_____________ TOTAL TIME:__________ TOTAL MILES:_____________ DRIVER OUT:____________________ DRIVER IN:____________________ MANAGER OUT:____________________ MANAGER IN:____________________ TOTAL KEYS REQUIRED: 6 ====================== AS BW ML RI SH US Into this:DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: A D:50 F:44 DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: B D:38 F:39 DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: C D:50 F:48 DELIVERY DATE: 30.10.2013 ROUTE: 13 DRIVER: H D:39 F:33 --->___Drink___Totals:__Fluoride___<--- 210 164 So if you save the first text as "anything.txt" compile the code below and then drag & drop "anything.txt" on the resulting EXE....Voila.expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=blue_water_leak.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** If $CmdLine[0] <> 0 Then $varpath = $CmdLine[1] EndIf #include <Date.au3> #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <Array.au3> Global $_DsumArray[0] Global $_FsumArray[0] Local $D1 Local $F1 Local $D2 Local $F2 Local $D3 _prepareArray() _addSums() Func _prepareArray() Global $aArray = FileReadToArray($varpath) Local $iRows = UBound($aArray) / 46 ConsoleWrite("$iRows = " & $iRows & @CRLF) Local $iCut = StringLeft($iRows, 1) ConsoleWrite("$iCut = " & $iCut & @CRLF) If @error Then MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file. Else For $i = 1 To $iCut ConsoleWrite("$i = " & $i & @CRLF) _extractFromArray() Next EndIf EndFunc ;==>_prepareArray Func _extractFromArray() Local $file2 = FileOpen("WaterOrder.txt", 1) ;file to write to Local $extractedarray = _ArrayExtract($aArray, 0, 47) ;~ _ArrayDisplay($extractedarray, "$extractedarray") ;================================================================== Local $value = _ArraySearch($extractedarray, "DELIVERY DATE:", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) FileWriteLine($file2, $writeLine) ;================================================================== Local $value = _ArraySearch($extractedarray, "ROUTE:", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) FileWriteLine($file2, $writeLine) ;================================================================== Local $value = _ArraySearch($extractedarray, "DRIVER:", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) FileWriteLine($file2, $writeLine) ;================================================================== Local $value = _ArraySearch($extractedarray, "P18X", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) If $value = -1 Then $D1 = 0 Else $writeLine = StringStripWS($writeLine, 2) $D1 = StringRight($writeLine, 3) EndIf ;================================================================== Local $value = _ArraySearch($extractedarray, "P19X", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) If $value = -1 Then $F1 = 0 Else $writeLine = StringStripWS($writeLine, 2) $F1 = StringRight($writeLine, 3) EndIf ;================================================================== Local $value = _ArraySearch($extractedarray, "P20X", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) If $value = -1 Then $D2 = 0 Else $writeLine = StringStripWS($writeLine, 2) $D2 = StringRight($writeLine, 3) EndIf ;================================================================== Local $value = _ArraySearch($extractedarray, "P24X", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) If $value = -1 Then $F2 = 0 Else $writeLine = StringStripWS($writeLine, 2) $F2 = StringRight($writeLine, 3) EndIf ;================================================================== Local $value = _ArraySearch($extractedarray, "P27X", "", "", 1, 1) Local $writeLine = _ArrayToString($extractedarray, "", $value, $value) ConsoleWrite("$writeLine = " & $writeLine & @CRLF) If $value = -1 Then $D3 = 0 Else $writeLine = StringStripWS($writeLine, 2) $D3 = StringRight($writeLine, 3) EndIf ;================================================================== ; sum of all things Local $D_sum = Execute($D1 + $D2 + $D3) ConsoleWrite("$D_sum = " & $D_sum & @CRLF) _ArrayAdd($_DsumArray, $D_sum) FileWriteLine($file2, "D:" & $D_sum) Local $F_sum = Execute($F1 + $F2) ConsoleWrite("$F_sum = " & $F_sum & @CRLF) _ArrayAdd($_FsumArray, $F_sum) FileWriteLine($file2, "F:" & $F_sum) Local $sRange = "0 -47" _ArrayDelete($aArray, $sRange) FileClose($file2) EndFunc ;==>_extractFromArray Func _addSums() Local $file2 = FileOpen("WaterOrder.txt", 1) ;file to write to FileWriteLine($file2, " --->___Drink___Totals:__Fluoride___<--- ") $Dsum = _ArrayToString($_DsumArray, "+") $Fsum = _ArrayToString($_FsumArray, "+") $Dsum = Execute($Dsum) ConsoleWrite("$Dsum = " & $Dsum & @CRLF) $Fsum = Execute($Fsum) ConsoleWrite("$Fsum = " & $Fsum & @CRLF) $Drack = Round($Dsum / 30) ConsoleWrite("$Drack = " & $Drack & @CRLF) $Frack = Round($Fsum / 30) ConsoleWrite("$Frack = " & $Frack & @CRLF) FileWriteLine($file2, "Btls " & $Dsum & " " & $Fsum) FileWriteLine($file2, "Racks " & $Drack & " " & $Frack) FileClose($file2) EndFunc ;==>_addSums Edited September 25, 2015 by l3ill update My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
l3ill Posted September 24, 2015 Author Share Posted September 24, 2015 Had to add a product and fix some bugs...Uploaded a zip file so it is easier to download and test.cya,Bill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example 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