Ghost21 Posted March 4, 2009 Share Posted March 4, 2009 (edited) Ok so I need a good kick in the a$$ in the right direction here and maybe just having a bad brain fart day. I need to get the pieces from the Total amount of pieces read line " Once " then the following Piece Quantity line to end of Piece line "----------" put in a array to be sent to a database ( got the database part done ). I have to do this whatever many times or the total piece quantity or EOF. The least amount of file manipulation as possible. PLease help..! CODE ;~ 3 ; The first 7 lines are just to show that its a version 3 file. ;~ 1 ;~ 0 ;~ 0 ;~ 0 ;~ 0 ;~ 0 ;~ 21 <---- Total amount of pieces in the file ;~ 2 <---- Piece Quantity ;~ ; j07a095g <---- Job Description ;~ 31 <---- Piece Type ;~ 0.291667 <---- Size ;~ 0.125 <---- Width ;~ 0 <---- Grade # ;~ SP2 <---- Grade Name ;~ (PW,GS5,2) <---- Piece Label ;~ 0 <---- Duplication Flag " 0 = False " ;~ 3.880169 <---- Top Length ;~ 3.588541 <---- Bottom Length ;~ 4.026002 <---- Long Length ;~ 3.734375 <---- Center Length ;~ 5 <---- Nominal Length ;~ 0 <---- # of Real Pts ;~ 4 <---- # of Rotated Pts ;~ 0.437461 <---- # of Rotated Pts ;~ 0 <---- # of Rotated Pts ;~ 0 <---- # of Rotated Pts ;~ 0.291667 <---- # of Rotated Pts ;~ 3.880169 <---- # of Rotated Pts ;~ 0.291667 <---- # of Rotated Pts ;~ 4.026002 <---- # of Rotated Pts ;~ 0 <---- # of Rotated Pts ;~ 4 <---- # Bevels ;~ 0 <---- Angles ;~ 90 <---- Angles ;~ 90 <---- Angles ;~ 0 <---- Angles ;~ 0 <---- Angles ;~ 90 <---- Angles ;~ 90 <---- Angles ;~ 0 <---- Angles ;~ 0 <---- Angles ;~ 90 <---- Angles ;~ 90 <---- Angles ;~ 0 <---- Angles ;~ 0 <---- Angles ;~ 90 <---- Angles ;~ 90 <---- Angles ;~ 0 <---- Angles ;~ ---------- <---- End of Piece line 1 ; j07a095g 11 0.291667 0.125 0 SP2 (PW,B1L,1) 0 12.001144 11.713541 12.001144 12 12 0 5 0 0 0 0.291667 12.001144 0.291667 12.001144 0.143802 11.713541 0 5 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 1 ; j07a095g 11 0.291667 0.125 0 SP2 (PW,B1R,1) 0 14.001144 13.713541 14.001144 14 14 0 5 0 0 0 0.291667 14.001144 0.291667 14.001144 0.143802 13.713541 0 5 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 21 0.291667 0.125 0 SP2 (PW,W2,2) 0 3.741287 3.583334 3.838527 3.817708 4 0 5 0.036483 0 0 0.291667 3.741287 0.291667 3.838527 0.145833 3.619817 0 5 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 21 0.291667 0.125 0 SP2 (PW,W1,2) 0 7.324669 7.166666 7.64063 7.640625 8 0 6 0.255233 0 0 0.145833 0.21873 0.291667 7.543399 0.291667 7.64063 0.145834 7.421899 0 6 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS4,2) 0 0.744713 0.161458 0.744713 0.453125 1 0 4 0.437421 0 0 0.291667 0.744713 0.291667 0.598879 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS1,2) 0 1.427083 1.28125 1.427083 1.354167 2 0 4 0 0 0 0.291667 1.427083 0.291667 1.28125 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS7,2) 0 1.880169 1.588541 2.026002 1.734375 3 0 4 0.437461 0 0 0.291667 1.880169 0.291667 2.026002 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS2,2) 0 2.427083 2.28125 2.427083 2.354167 3 0 4 0 0 0 0.291667 2.427083 0.291667 2.28125 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS3,2) 0 2.598879 2.161458 2.598879 2.380208 3 0 4 0 0 0 0.291667 2.598879 0.291667 2.161458 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS6,2) 0 3.312461 2.875 3.312461 3.09375 4 0 4 0 0 0 0.291667 3.312461 0.291667 2.875 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- CODE #include <file.au3> ;---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Dim $FILE_NAME = @DesktopDir & "\J07A095G-P1-1.trs" Dim $FILE_SIZE = FileGetSize(@DesktopDir & "\J07A095G-P1-1.trs") ;---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Dim $TOTAL_PIECES <-- Only on line " 8 " Dim $PIECE_QUANTITY Dim $JOB_DESCRIPTION Dim $PIECE_TYPE Dim $Size Dim $Width Dim $Grade Dim $GRADE_NAME Dim $PIECE_LABEL Dim $DUPLICATION_FLAG Dim $TOP_LENGTH Dim $BOTTOM_LENGTH Dim $LONG_LENGTH Dim $CENTER_LENGTH DIM $NOMINAL_LENGTH DIM $NUMBER_OF_REAL_POINTS DIM $NUMBER_OF_ROTATED_POINTS1 DIM $NUMBER_OF_ROTATED_POINTS2 DIM $NUMBER_OF_ROTATED_POINTS3 DIM $NUMBER_OF_ROTATED_POINTS4 DIM $NUMBER_OF_ROTATED_POINTS5 DIM $NUMBER_OF_ROTATED_POINTS6 DIM $NUMBER_OF_ROTATED_POINTS7 DIM $NUMBER_OF_ROTATED_POINTS8 DIM $NUMBER_OF_ROTATED_POINTS9 DIM $NUMBER_OF_BEVELS DIM $BEVEL_ANGLE1 DIM $BEVEL_ANGLE2 DIM $BEVEL_ANGLE3 DIM $BEVEL_ANGLE4 DIM $BEVEL_ANGLE5 DIM $BEVEL_ANGLE6 DIM $BEVEL_ANGLE7 DIM $BEVEL_ANGLE8 DIM $BEVEL_ANGLE9 DIM $BEVEL_ANGLE10 DIM $BEVEL_ANGLE11 DIM $BEVEL_ANGLE12 DIM $BEVEL_ANGLE13 DIM $BEVEL_ANGLE14 DIM $BEVEL_ANGLE15 DIM $BEVEL_ANGLE16 DIM $END_OF_PIECE ;----------------------------------------------------------------------------------------------------------------------------------------------------------------------0 Edited March 4, 2009 by SmOke_N Added codebox tags for lengthy example text(s) Link to comment Share on other sites More sharing options...
Skruge Posted March 4, 2009 Share Posted March 4, 2009 I need to get the pieces from the Total amount of pieces read line " Once " then the following Piece Quantity line to end of Piece line "----------" put in a array to be sent to a database ( got the database part done ). I have to do this whatever many times or the total piece quantity or EOF. The least amount of file manipulation as possible.From your description, it's not clear if you want all the data separated by record, or if you want only the Total and Quantities. Unless I'm reading it wrong, the "Total" (21) doesn't match the actual tally (2+1+1+2+2+2+2+2+2+2+2=20), so my method just reads the entire file. I used this file (comments stripped): CODE3 1 0 0 0 0 0 21 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS5,2) 0 3.880169 3.588541 4.026002 3.734375 5 0 4 0.437461 0 0 0.291667 3.880169 0.291667 4.026002 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 1 ; j07a095g 11 0.291667 0.125 0 SP2 (PW,B1L,1) 0 12.001144 11.713541 12.001144 12 12 0 5 0 0 0 0.291667 12.001144 0.291667 12.001144 0.143802 11.713541 0 5 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 1 ; j07a095g 11 0.291667 0.125 0 SP2 (PW,B1R,1) 0 14.001144 13.713541 14.001144 14 14 0 5 0 0 0 0.291667 14.001144 0.291667 14.001144 0.143802 13.713541 0 5 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 21 0.291667 0.125 0 SP2 (PW,W2,2) 0 3.741287 3.583334 3.838527 3.817708 4 0 5 0.036483 0 0 0.291667 3.741287 0.291667 3.838527 0.145833 3.619817 0 5 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 21 0.291667 0.125 0 SP2 (PW,W1,2) 0 7.324669 7.166666 7.64063 7.640625 8 0 6 0.255233 0 0 0.145833 0.21873 0.291667 7.543399 0.291667 7.64063 0.145834 7.421899 0 6 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS4,2) 0 0.744713 0.161458 0.744713 0.453125 1 0 4 0.437421 0 0 0.291667 0.744713 0.291667 0.598879 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS1,2) 0 1.427083 1.28125 1.427083 1.354167 2 0 4 0 0 0 0.291667 1.427083 0.291667 1.28125 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS7,2) 0 1.880169 1.588541 2.026002 1.734375 3 0 4 0.437461 0 0 0.291667 1.880169 0.291667 2.026002 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS2,2) 0 2.427083 2.28125 2.427083 2.354167 3 0 4 0 0 0 0.291667 2.427083 0.291667 2.28125 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS3,2) 0 2.598879 2.161458 2.598879 2.380208 3 0 4 0 0 0 0.291667 2.598879 0.291667 2.161458 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- 2 ; j07a095g 31 0.291667 0.125 0 SP2 (PW,GS6,2) 0 3.312461 2.875 3.312461 3.09375 4 0 4 0 0 0 0.291667 3.312461 0.291667 2.875 0 4 0 90 90 0 0 90 90 0 0 90 90 0 0 90 90 0 ---------- #include <Array.au3> ;---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Local $FILE_NAME = @DesktopDir & "\J07A095G-P1-1.trs" ;---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Local $a_TRS_Lines, $s_TRS_File, $a_TRS_Records, $i_Total, $i_Tally ; Read and parse the file $s_TRS_File = StringStripWS(FileRead($FILE_NAME), 3) $a_TRS_Lines = StringSplit($s_TRS_File, "----------", 1) For $iX = 1 To $a_TRS_Lines[0] - 1 $a_TRS_Records = StringSplit(StringStripWS($a_TRS_Lines[$iX], 3), @CRLF, 1) If $iX = 1 Then ; Read the "Total amount of pieces" $i_Total = $a_TRS_Records[8] ConsoleWrite("Total amount of pieces (according to line 8) : " & $i_Total & @CRLF) ; Strip out the first 8 lines For $iY = 1 To 8 _ArrayDelete($a_TRS_Records, 1) Next $a_TRS_Records[0] -= 8 EndIf ; Add up the pieces $i_Tally += $a_TRS_Records[1] ConsoleWrite("Piece Quantity: " & $a_TRS_Records[1] & @TAB & "Running Total: " & $i_Tally & @CRLF) ;~ _ArrayDisplay($a_TRS_Records, "Record " & $iX & " of " & $a_TRS_Lines[0] - 1) Next Uncomment the _ArrayDisplay line if you want to see the individual records as arrays. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] 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