Unwanted CRLF in row written to file

Started by Mykal, June 23, 2023, 12:59:19 AM

Previous topic - Next topic

Mykal

I hope the few lines of code are going to show up below.  There are 3 oChoices for Item85 in the code and Choices 1 & 2 give rubbish results in that that they create a CRLF after the first item in the line to be written.  Choice 3 works well but, obviously, I cant supply a text line for each debtor.  Choice 1 is the option I would like to use.   How can I avoid the CRLF ????



Item82 = "AL44999"                                            ;Debtor's Code
Item83 = FileGet("AL44999.txt")                           ;Debtor's file
Item84 = ItemCount (Item83, @TAB)
Item85 = ItemExtract(-1,Item83,@TAB)                ;1st Choice. Retrieve the last item in the File
;Item85 = ItemExtract(Item84-1,Item83,@TAB)    ;2nd Choice. Retrieve the last item in the File
;Item85 = "21-06-2023,Annual Subscription,5.00,390.0,   "        ;3rd Choice. This option produces the only correct result
Item91 = ItemExtract(1,Item85,",")                     ;Extract the Date
Item92 = ItemExtract(4,Item85,",")                     ;Extract the Balance Owing
Item93 = StrCat(Item82,",",Item91,",",Item92,",",@TAB)
message("Item93",Item93)

DropWild("Item*")

Exit


Last few transactions in Debtor's file "AL44999.txt"

18-06-2023,Annual Subscription,-5.00,375.0,   
18-06-2023,Annual Subscription,5.00,380.0,   
21-06-2023,Annual Subscription,5.00,385.0,   
21-06-2023,Annual Subscription,5.00,390.0,   

kdmoyers

I'm a bit pressed for time, but my quick guess is this line
Code (winbatch) Select
Item85 = ItemExtract(-1,Item83,@TAB)
is grabbing the line ending on the end of the last line, and that is carried along to later variables.
You might try closely examining the Item85 var after that line to see if that's there.
If so, maybe trim it off?

$0.02
The mind is everything; What you think, you become.

JTaylor

The code would lead one to believe this is a one line file of @TAB delimited data.  If so,

Item83 = StrReplace(FileGet("AL44999.txt"),@CRLF,"")

Should do what you want, as Kirby noted.

Jim

td

Assuming the file is either carriage return/line feed or just line feed row terminated and that there are not other saliant points going unmentioned, the following may work

Code (winbatch) Select
; Used Notpad to create a file called junk.txt
; with the following 4 lines.
;18-06-2023,Annual Subscription,-5.00,375.0,   
;18-06-2023,Annual Subscription,5.00,380.0,   
;21-06-2023,Annual Subscription,5.00,385.0,   
;21-06-2023,Annual Subscription,5.00,390.0,   

Item82 = "AL44999"                                     ;Debtor`s Code
Item83 = FileGet("testdata\Junk.txt")
Item84 = StrReplace(Item83, @CR, "")  ; In case it is @CRLF terminated.
Item85 = ItemExtract(-1, Item84, @lf)
Item91 = ItemExtract(1,Item85,",")                     ;Extract the Date
Item92 = ItemExtract(4,Item85,",")                     ;Extract the Balance Owing
Item93 = StrCat(Item82,",",Item91,",",Item92,",",@lf)
message("Item93",Item93)

exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Mykal

Thanks Guys.  I'm not sure why the following has worked but replacing @TAB with @LF in both Item84 and (2nd Choice) Item85 seems to do the trick.  Thanks for your inspiration and help.  Cheers, Mike.