PDA

View Full Version : carriage return, no line feed



hcrisp
11-13-2008, 01:23 PM
How do I print a line over itself using iterative PRINT statements? I want to update a progress indicator such as:


Updating file: 98.2%

In other words, I want to print a carriage return, but not a linefeed. I am using Windows XP. It should be implemented in this type of loop:


FOR i=0L, nlines DO BEGIN
PRINT, 'Updating file: ' + STRING(100 * i / nlines) + '%' ; no linefeed here
...
ENDFOR

totallyunimodular
11-13-2008, 08:12 PM
Try something like
str = 'Updating file: ' + STRING(100 * i / nlines, Format='(F4.1)') + '%'
PRINT, str, Format='(A23, $)'

The "$" in the format statement suppresses the linefeed.

Cheers

hcrisp
11-14-2008, 12:22 PM
Thanks. Worked just fine! I used the following syntax:


pct = STRING(STRTRIM(NINT(100. * (i+1) / nlines), 2), FORMAT='(A3)') + '%'
str = 'Updating file: ' + pct + STRING(13B)
nstr = STRTRIM(STRLEN(str), 2)
PRINT, str, FORMAT='(A' + nstr + ', $)'