Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alternate has blank line??

Status
Not open for further replies.

FB9

Technical User
Oct 14, 2006
9
US
If I do "set alte to xxx", and "set alte on", type a line like "? test", then "close alte", and take a look at xxx.txt, there is a blank line at the top of the file. This is causing a problem in my application... I want the text to start on the first line.

Any thoughts/solutions???

Thanks!
 
Hi, FB9

If you use ? to print then whatever you print is prefixed with a carriage return/line feed (chr(10)+chr(13)).

To suppress that, use ?? instead.

However, if you want the crlf at the end of the line then you will either have use ? on all subsequent lines or put out crlf's explicitly where/if needed.

Jock
 
Thanks, JockMullin... only trouble is, that doesn't seem to work! If I substitute ??"test" right after "set alte on", it puts the lines together on the alte file, but there's still the blank line before all that.

How can I get NOT generate that blank line (or get rid of it)??!!

Frank
 
Hi, Frank

I just compiled the following prog here:

set alternate to test.txt
set alternate on
set console off
?? "TEST"
set console on
set alternate off
set alternate to

After running it the output file test.txt is a 5 byte file. Looking at it with a hex editor it contains "TEST" followed by ascii 1A - the DOS end of file character. No blank line.

What version of Clipper are you using? I tested with Clipper Summer ;87, 5.2e and xHarbour 0.99.60 and all produced identical output.

Jock
 
Frank,

I have seen this before, it's phsyically buts a blank line at the very top of the output. I've just worked around it and haven't ever figured our why.

Thanks,

Jim C.
 
Here's a code clip from my "837 EDI file generator" program. I had the same problem that I had to work around. Here is the current code.

Code:
SET ALTERNATE TO ( cFileName )  //  file info is stored in
SET ALTERNATE ON
SET CONSOLE OFF

?? ISA(cSenderIdISA, cRcvrIdISA , cInterchangeNum)  //Interchange
?? GS( cSenderIdGS , cRcvrIdGS  , cGroupNum)  // Group Header

The trick might be SET CONSOLE OFF, but this code works in my application.

Jim Rumbaugh
 
Well, maybe Frank is typing the commands into a dot prompt.
In that case you can't set console off, and when the prompt is displayed or command window is cleared maybe that is also being sent to the output file.

In any case, if the amount of text you want to write into the file isn't too large, you could use memowrit() instead. Then it would be just one line:

memowrit("test.txt","TEST")

That also gets me just a 5-byte test.txt file as before.

And then there are also the low level file functions, but the set alternate method SHOULD work - I do it all the time to write CSV files and my header line is indeed the first line.

Jock (scratching head).
 
Thanks, everyone... got it solved, but am still not certain what the deal was... seemed to get inconsistent results. You're right, JockMullin, I was typing into a dot prompt for trial purposes, then just made a plain .prg file for test purposes, finally realized I couldn't legitimately test that way, so compliled it. I think the answer was your original suggestion... use ?? rather than ?... I'd just tried it at the dot prompt and it didn't help. Set console on/off didn't seem to make a difference.

Anyway, thanks again for all the feedback!!

Frank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top