Clear Globals(); Clear Log(); PATHimport = Pick Directory( "Select Invoice Directory" ); Listoflogs = Files In Directory( PATHimport ); //Show all files in directory in Log Show( LISTOFLOGS ); For( i = N Items( LISTOFLOGS ), i >= 1, i--, If( !Ends With( Uppercase( LISTOFLOGS[i] ), ".TXT" ), Remove From( LISTOFLOGS, i ) ) ); //Show Files in directory remaining after filtering Show( LISTOFLOGS ); //Assign Varibles to be used in future var_INV_No = {}; var_INV_Date = {}; var_Comp = {}; var_B_Add = {}; var_Sh_Add = {}; var_Sh_Met = {}; var_QTY = {}; var_Pro_Des = {}; var_EA = {}; var_Amount = {}; var_list={}; //Creat script to be used later Script1= Expr( var_INV_No = Insert( var_INV_No, YY ) ; var_INV_Date = Insert( var_INV_Date, XXi ); var_Comp =Insert( var_Comp, WW ); var_B_Add = Insert( var_B_Add, VV ) ; var_Sh_Add = Insert( var_Sh_Add , UU ); var_Sh_Met =Insert( var_Sh_Met, TT)); //Begin For loop to process Files in Directory Print(Asdate(Start=Today())); For( Z = 1, Z <= 20, Z++, var_List={}; //Open Invoice as a Script NW = Open( PATHimport || LISTOFLOGS[Z], Script, window bounds( 232, 232, 331, 331 ), window state( minimized ) ); //It's important to realize that all scripts, or in this case text opened in a script window, //are actually a New Window and script box and to interact with the text you must assign //script box a global to interact with the text. ::Obj_INV = NW[Script Box( 1 )]; //Determine how many lines in invoice var_lc = ::Obj_INV << get line count(); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Clean up Data_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Fix rows impacted by hyphen For( A =1, A <=var_lc, A++, AA = ::Obj_INV << get line text( A ); //Check for strings ending in Hyphen If( (right( AA, 1)=="-"), //Get line following and add to orginal text (AA = ::Obj_INV << get line text( A ); AAz = ::Obj_INV << get line text( A+1) ; //Jion text pieces together AAy=AA||AAz ; Print(AAy); Print( A ); //Reset lines of text ::Obj_INV << set line text( A, AAy ); ::Obj_INV <0), //Get line following and add to orginal text BB = Munger( BB, 0, ", ", " " ) ; BB = Munger( BB, 1, "\!" x 11\!",", " x 11" ) ; //Reset lines of text ::Obj_INV << set line text( B, BB ); );//end of If ); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Invoice Number_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find line containing "Invoice Number: " For( Y = 4, Y<= 10, Y++, ZZ = ::Obj_INV << get line text( Y ); //Compare text to "Company:" If( Contains( ZZ, "Invoice Number:" ), //Get line following and add to List of Company names (YY = ::Obj_INV << get line text( Y ) ; //Strip "Invoice Number: " from text YY = Munger( YY, 1, "Invoice Number: ", "" ) ; //Add invoice number to string var_INV_No = Insert( var_INV_No, YY ) ; ) ); //end of If ); Print(var_INV_No); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Date_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find line containing "Invoice Date:" For( X = 6, X <= 10, X++, XX = ::Obj_INV << get line text( X ); //Compare text to "Invoice Date:" If( Contains( XX, "Invoice Date:" ), //Get line contianing Invoice Date: (XX = ::Obj_INV << get line text( X ) ; //Strip "Invoice Number: " from text XXi = Munger( XX, 1, "Invoice Date:", "" ) ; //Add invoice number to string var_INV_Date = Insert( var_INV_Date, XXi ) ; ) ); //end of If ); Print(var_INV_Date); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Company_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find line containing "Company:" For( W = 14, W <=30, W++, WW = ::Obj_INV << get line text( W ); //Compare text to "Company:" If( WW == "Company:", //Get line following and add to List of Company names (WW = ::Obj_INV << get line text( W + 1 ) ; var_Comp =Insert( var_Comp, WW ) ; W = var_lc) );//end of IF ); Print(var_Comp); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Buisness Address_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find 1st line containing "Address:" For( V = 1, V<=30, V++, VV = ::Obj_INV << get line text( V ); //Compare text to "Address:" If( VV == "Address:", //Get line following and hold for future use (V1 = ::Obj_INV << get line text( V + 1 ) ; //Find 1st line containing "City/State/Zip" For( Vi = 32, Vi <= 40, Vi++, VVi = ::Obj_INV << get line text( Vi ); //Compare text to "City/State/Zip" If( VVi == "City/State/Zip", //Get line following and add hold (VVi = ::Obj_INV << get line text( Vi + 1 )); Vi = var_lc; ); ) ; //Add "City/State/Zip" to Buisness Address VV = Concat( V1, " ", VVi ) ; //Add combined varibale to list var_B_Add = Insert( var_B_Add, VV ) ; V = var_lc) ); ); Print(var_B_Add); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Shipping Address_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find 1st line containing "Address:" For( U = 20, U<=30, U++, UU= ::Obj_INV << get line text( U); //Compare text to "Company:" If( UU == "Address:", //Get line following and hold for future use (UU = ::Obj_INV << get line text( U + 3 ) ; //Find 1st line containing "City/State/Zip" For( Ui = 32, Ui <= 40, Ui++, UUi = ::Obj_INV << get line text( Ui ); //Compare text to "City/State/Zip" If( UUi == "City/State/Zip", //Get line following and hold for future use (UUi = ::Obj_INV << get line text( Ui + 3 )); Ui = var_lc; ); ) ; //Add "City/State/Zip" to Buisness Address UU = Concat( UU, " ", UUi ) ; //Add combined varibale to list var_Sh_Add = Insert( var_Sh_Add , UU ) ; U = var_lc) );//end of 1st If ); Print(var_Sh_Add); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Shipping Method_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find 1st line containing "Method:" For( T = 30, T<=50, T++, TT = ::Obj_INV << get line text( T ); //Compare text to "Method:" If( TT == "Method:", //Get line following and add to List of Company names (TT = ::Obj_INV << get line text( T + 1 ) ; var_Sh_Met =Insert( var_Sh_Met, TT) ; T = var_lc) );//end of if ); Print(var_Sh_Met); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Qty_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find 1st line containing "Qty" For( S = 40, S<=var_lc, S++, SS = ::Obj_INV << get line text( S ); //Compare text to "Qty" If( SS == "Qty", //Get multiple lines containing Qtys For( Si = 4, Si<=var_lc, Si++, (SSi = ::Obj_INV << get line text( S + Si ) ; //Compare text to number value or if it contains $ If( And( Num( SSi ) > 0, Contains( SSi, "$" )==0 ), //Get current line caontaining Qty and add to list of Qtys (var_QTY = Insert( var_QTY, SSi ); //Prepare list to be used in future evaluations var_S = S + Si; var_list = Insert( var_List, var_S ); If(nitems(var_List)>1,Script1) ), SSi == "Subtotal:", Si = var_lc; S= var_lc )//end 2nd If ) )//end of 2nd For );//end of 1st If );//end of 1st For // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Product Description_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ //Find Product Descriptions For( R = 1, R <= N Items( var_List ), R++, RR = ::Obj_INV << get line text( var_List[R] + 1 ); If( RR == "Subtotal:", R = var_lc );//end of 1st If //Compare text to If( !Contains( RR, "$" ), var_Pro_Des = Insert( var_Pro_Des, RR ); );//end of 2nd If ); // ,.-~*´¨¯¨`*·~-.,.-~*´¨¯¨`*·~-.¸-(_Product Price_)-,.-~*´¨¯¨`*·~-.¸,.-~*´¨¯¨`*·~-.¸ Qi = 0; For( Q =var_List[1], Q<= var_lc , Q++, QQ = ::Obj_INV << get line text( Q ); If( QQ == "Subtotal:", Q = var_lc );//end of 1st If //Find text with $ If( Contains( QQ, "$" ), (If( Qi == 0, (var_EA = Insert( var_EA, QQ ) ; Qi = 1), If( Qi == 1, var_Amount = Insert( var_Amount, QQ ); Qi = 1; ),//end of 4th If Qi = 0 );//end of 3rd If ); );//end of 2nd If ); Wait(0.001); NW<