View previous topic :: View next topic |
Author |
Message |
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Thu Jan 09, 2014 6:49 am Post subject: CRLF inside file |
|
|
I have been banging my head against this for several hours. I have a subroutine that writes an error file to an SD card every 15 minutes. The error_msg gets built up event by event during the previous 15 minutes. The code looks like this, and works fine.
Code: |
'**********************************************
'generates the error_message
error_msg = error_msg + "read error at ";datetimestr
'***********************************************
|
Code: |
'***********************************************************************
Write_to_errorlog:
'--------------------------------------------------------------------------------------
'Appends current error message to SD card file and creates file if file not exist.
'
'--------------------------------------------------------------------------------------
gosub sd_error_check
Disable Interrupts
Chdir "\" 'to root
Mkdir "Errorlog" 'mk dir if not exist
Chdir "\"
Chdir "Errorlog"
Myfilename = "error___.txt"
Open Myfilename For Binary As #128
Filelength = Lof(#128)
Filelength = Filelength + 1 'find where to append
Seek #128 , Filelength 'set pointer
Tempb = Len(error_msg)
Put #128 , Error_msg , , Tempb
Cr = 13 : Lf = 10
Put #128 , Cr , , 1 'CRLF between records
Put #128 , Lf , , 1
Flush #128
Close #128
Print #1 , ">> Entry saved to errorlog " 'debug port
Print #1 , ""
Chdir "\" 'back to root dir
Error_msg = ""
Enable Interrupts
Return
'*********************************************************************** |
If my error_msg is a quite long such as " the quick brown fox jumps over the fat and lazy dog. there is a temperature error. there is a time error',
then the log file is seen over several lines with notepad and looks clumsy, so i want to embed a crlf in the text as i build the error file in code.
Like this:
Code: |
error_msg = error_msg + "read error at ";datetimestr + chr(10)+ chr(13)
|
This would mean that each error event would be viewed on a separate line.
But - that doesn't work, and nor have any of the other variations I have tried, and I have run out of ideas.
Incidently this line in my write file routine does work
Code: |
Put #128 , Cr , , 1 'CRLF between records
Put #128 , Lf , , 1 |
and every new write to the SD card is separated by a CRLF, but I cant seem to be able to add additional CRLF embedded in my error string, as it gets built up. _________________ Neil |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Jan 09, 2014 10:14 am Post subject: |
|
|
for windows you must use chr(13)+ chr(10) , not chr(10)+ chr(13) _________________ Mark |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Thu Jan 09, 2014 10:54 am Post subject: |
|
|
the order matters? _________________ Neil |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Jan 09, 2014 2:39 pm Post subject: |
|
|
to notepad and most windows editors it does. Just create a text file and look with a binary viewer or editor or just test it. _________________ Mark |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Fri Jan 10, 2014 12:39 am Post subject: |
|
|
Thankyou Mark. That was indeed the problem. I never thought to try them in the other (correct) order. _________________ Neil |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|