I have an application where I run a report and save it to a .txt file one day and then run the same report the next day and save that to a different .txt file. I have created a script to compare the two files line by line and then create a thrid file showing what has not changed.
My problem comes in with using the "WriteLn" function. Because the data in the files contain commas {","}, I can not transfer the complete line becasue when the first comma is found, everything up to the comma is stripped away.
I have been able to use the "Send Character/Text" function successfully, but this means that the file must be created with the notepad window open and it also takes longer to run.
Is there a work around to this problem with the comma?
A sample of what the line I am trying to write is as follows:
42072 001 B01010J037004 BODY,.985,1.00 ENG,36.87 LG 15 MS 086 R 9/27/2006 400 00074302
Rory
Comma problem with WriteLn
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Hi,
Commas are no problem. This works fine for me:
Commas are no problem. This works fine for me:
Code: Select all
Let>line=this is some text, with commas, writeln handles it no problem
WriteLn>c:\test.txt,res,line
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I have tried the "MessageModal>" function and it works.
I am posting the script but it will not work unless you have the source files to read from. I can provide them if needed.
Look for the line that is *** all the way accross and that is where the WLN command is.
Rory
GetDate>date
Hour>Hour
Min>Minutes
If>{(%Hour%>12)OR(%Hour%=12)}
Let>AmPm=PM
ELSE
Let>AmPm=AM
ENDIF
If>%Hour%>12
Let>Hour=Hour-12
ENDIF
Let>SkipLineBreak=0
Let>LineBreak=%CR%---------------------------------------------------------------------------------------------------------------------%CRLF%
Let>SourceFile1=C:\TCM_Reports\Report.txt
Let>SourceFile2=C:\TCM_Reports\Report2.txt
Let>DestinationFile=C:\TCM_Reports\Report3.txt
WLN>%DestinationFile%,SF-PRIORITIES%CRLF%%CRLF%PRIORITIES THAT HAVE SAT AT LEAST ONE DAY%CRLF%
WLN>%DestinationFile%,%date% %Hour%:%Minutes% %AmPm%%CRLF%
Let>HeaderLine1= Shop S/O Parent Item Item description Oper Dept W/C Rec Oper Due Oper Order
Let>HeaderLine2= Order Sufx Stat Date Prty Ref
WLN>%DestinationFile%,%HeaderLine1%
WLN>%DestinationFile%,%HeaderLine2%%CRLF%
WLN>%DestinationFile%,---------------------------------------------------------------------------------------------------------------------%CRLF%
ExecuteFile>%DestinationFile%
WaitWindowOpen>Report3.txt - Notepad
SetFocus>Report3.txt - Notepad
Press Ctrl
Press End
Release Ctrl
Let>SK_DELAY=0
//**BREAKPOINT**
Let>m=8
Let>z=1
Label>StartReadLoop
ReadLn>%SourceFile1%,m,SourceLine
If>%SourceLine%=##EOF##,EndOfFileMessage
If>%SourceLine%=##NOFILE##,NoFileMessage
If>%SourceLine%=
Let>m=m+1
GOTO>StartReadLoop
ENDIF
MidStr>%SourceLine%,1,82,somevalue
MidStr>%SourceLine%,6,6,CountFile1
Let>m=m+1
Label>StartScanLoop
ReadLn>%SourceFile2%,z,result
If>%result%=
Let>z=z+1
GOTO>StartScanLoop
ENDIF
MidStr>%result%,1,82,ValueResult
MidStr>%result%,6,6,CountFile2
If>%result%=##EOF##
Let>z=1
GOTO>StartReadLoop
ENDIF
Let>Count=count:
If>{(%CountFile1%=%Count%)AND(%CountFile2%=%Count%)}
IF>SkipLineBreak=0
Let>SkipLineBreak=1
// WriteLn>%DestinationFile%,%LineBreak%
Send>%LineBreak%
Let>z=1
GOTO>StartReadLoop
ELSE
Let>z=1
GOTO>StartReadLoop
ENDIF
ENDIF
If>%somevalue%=%ValueResult%
If>%SourceLine%=%HeaderLine1%
Let>z=z+1
GOTO>StartScanLoop
ENDIF
If>%SourceLine%=%HeaderLine2%
Let>z=z+1
GOTO>StartScanLoop
ENDIF
//************************************************************
//this is where I am having the problem
// MessageModal>%SourceLine%
// WriteLn>%DestinationFile%,%SourceLine%%CR%
Send>%SourceLine%%CR%
Let>SkipLineBreak=0
Let>z=1
GOTO>StartReadLoop
ELSE
Let>z=z+1
GOTO>StartScanLoop
ENDIF
Label>EndOfFileMessage
Message>%CRLF%%CRLF% **Report is complete!**
GOTO>end
Label>NoFileMessage
Message>Source file "C:\TCM_Reports\Report.txt" does not exist!
Label>end
I am posting the script but it will not work unless you have the source files to read from. I can provide them if needed.
Look for the line that is *** all the way accross and that is where the WLN command is.
Rory
GetDate>date
Hour>Hour
Min>Minutes
If>{(%Hour%>12)OR(%Hour%=12)}
Let>AmPm=PM
ELSE
Let>AmPm=AM
ENDIF
If>%Hour%>12
Let>Hour=Hour-12
ENDIF
Let>SkipLineBreak=0
Let>LineBreak=%CR%---------------------------------------------------------------------------------------------------------------------%CRLF%
Let>SourceFile1=C:\TCM_Reports\Report.txt
Let>SourceFile2=C:\TCM_Reports\Report2.txt
Let>DestinationFile=C:\TCM_Reports\Report3.txt
WLN>%DestinationFile%,SF-PRIORITIES%CRLF%%CRLF%PRIORITIES THAT HAVE SAT AT LEAST ONE DAY%CRLF%
WLN>%DestinationFile%,%date% %Hour%:%Minutes% %AmPm%%CRLF%
Let>HeaderLine1= Shop S/O Parent Item Item description Oper Dept W/C Rec Oper Due Oper Order
Let>HeaderLine2= Order Sufx Stat Date Prty Ref
WLN>%DestinationFile%,%HeaderLine1%
WLN>%DestinationFile%,%HeaderLine2%%CRLF%
WLN>%DestinationFile%,---------------------------------------------------------------------------------------------------------------------%CRLF%
ExecuteFile>%DestinationFile%
WaitWindowOpen>Report3.txt - Notepad
SetFocus>Report3.txt - Notepad
Press Ctrl
Press End
Release Ctrl
Let>SK_DELAY=0
//**BREAKPOINT**
Let>m=8
Let>z=1
Label>StartReadLoop
ReadLn>%SourceFile1%,m,SourceLine
If>%SourceLine%=##EOF##,EndOfFileMessage
If>%SourceLine%=##NOFILE##,NoFileMessage
If>%SourceLine%=
Let>m=m+1
GOTO>StartReadLoop
ENDIF
MidStr>%SourceLine%,1,82,somevalue
MidStr>%SourceLine%,6,6,CountFile1
Let>m=m+1
Label>StartScanLoop
ReadLn>%SourceFile2%,z,result
If>%result%=
Let>z=z+1
GOTO>StartScanLoop
ENDIF
MidStr>%result%,1,82,ValueResult
MidStr>%result%,6,6,CountFile2
If>%result%=##EOF##
Let>z=1
GOTO>StartReadLoop
ENDIF
Let>Count=count:
If>{(%CountFile1%=%Count%)AND(%CountFile2%=%Count%)}
IF>SkipLineBreak=0
Let>SkipLineBreak=1
// WriteLn>%DestinationFile%,%LineBreak%
Send>%LineBreak%
Let>z=1
GOTO>StartReadLoop
ELSE
Let>z=1
GOTO>StartReadLoop
ENDIF
ENDIF
If>%somevalue%=%ValueResult%
If>%SourceLine%=%HeaderLine1%
Let>z=z+1
GOTO>StartScanLoop
ENDIF
If>%SourceLine%=%HeaderLine2%
Let>z=z+1
GOTO>StartScanLoop
ENDIF
//************************************************************
//this is where I am having the problem
// MessageModal>%SourceLine%
// WriteLn>%DestinationFile%,%SourceLine%%CR%
Send>%SourceLine%%CR%
Let>SkipLineBreak=0
Let>z=1
GOTO>StartReadLoop
ELSE
Let>z=z+1
GOTO>StartScanLoop
ENDIF
Label>EndOfFileMessage
Message>%CRLF%%CRLF% **Report is complete!**
GOTO>end
Label>NoFileMessage
Message>Source file "C:\TCM_Reports\Report.txt" does not exist!
Label>end
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Your WriteLn functions are ALL wrong. You've missed out the result variable. WriteLn takes THREE parameters. Note my example - which you confirmed works. See the difference?
So what is probably happening is all up to the first comma is being used as the result variable, the rest the line.
So what is probably happening is all up to the first comma is being used as the result variable, the rest the line.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?