Comma problem with WriteLn

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Rory
Pro Scripter
Posts: 50
Joined: Thu Mar 23, 2006 2:50 pm
Location: Wisconsin

Comma problem with WriteLn

Post by Rory » Fri Oct 06, 2006 11:54 am

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

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Oct 06, 2006 12:42 pm

Hi,

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?

Rory
Pro Scripter
Posts: 50
Joined: Thu Mar 23, 2006 2:50 pm
Location: Wisconsin

Post by Rory » Fri Oct 06, 2006 2:55 pm

Well, I must have something set wrong. I can get it to work in the sample you replied with but in my script it will not.
I will have to examine it closer.

Thanks for the reply.

If I figure out what I did wrong, I will post it, it may help someone else.

Rory

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Oct 06, 2006 3:44 pm

Worked perfectly for me too using your example line. Can you post more code? Maybe the line isn't getting assigned to the variable correctly, what happens if you use a messagemodal> to display it prior to writing to the file?

Rory
Pro Scripter
Posts: 50
Joined: Thu Mar 23, 2006 2:50 pm
Location: Wisconsin

Post by Rory » Fri Oct 06, 2006 4:36 pm

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

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Oct 06, 2006 4:41 pm

Beep, bad syntax.

WriteLn>%DestinationFile%,%SourceLine%%CR%

missing the result

WriteLn>c:\temp\test.txt,result,%date% - Starting Macro

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Oct 06, 2006 4:41 pm

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Rory
Pro Scripter
Posts: 50
Joined: Thu Mar 23, 2006 2:50 pm
Location: Wisconsin

Post by Rory » Fri Oct 06, 2006 5:09 pm

Yes you are correct. I changed the WLN line and it works perfectly.

Thanks much,
Rory

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts