At 01:24 PM 6/22/2004, you wrote:
>From: "Les Hazlett"
>I need to insert a 3 digit number (with leading zeros) into a text file - at the cursor. The number is in a numeric register and has a range of 1-999. I can put this number into a text register using Num_Str with the FILL option to get the leading zeros. However, I get a 5 digit number and I want it to be only 3. Is there some easy way to limit the number of characters in the text register so that I can simply use Reg_Ins to put it into the text file? Thanks for your help.
First of all, you can insert numbers directly into the file using the Num_Ins() command; you don't need to use Num_Str() and Reg_Ins().
Num_Ins() and Num_Str() are both based on Num_Type() and have exactly the same options.
These commands have some additional options which I haven't documented yet, but which do exactly what you want. Here is some sample code:
#1 = 99 //Numeric register 1 contains the number
Num_Ins(#1,SIMPLE+FILL+COUNT,3) //Insert #1 as an unsigned number in a
//field of 3 characters with leading zero
Note that you must use the "SIMPLE" option to specify this is an unsigned number; otherwise the first column is reserved for the sign.
Here is our internal doco on these commands with all options:
; Num_Ins(n) - Insert ASCII of 'n' into edit buffer. (ARG_NO)
; OPTIONS - same as for Num_Type()
; Num_Str(n,r) - Place ASCII of 'n' into T-Reg 'r'. (ARG_2N)
; Num_Str(n,r,APPEND) - Append ASCII of 'n' to end of T-Reg 'r'.
; Num_Str(n,r,INSERT) - insert ASCII of 'n' at beginning of T-Reg 'r'.
; Other OPTIONS - same as for Num_Type().
; Num_Type(n) - Type value of 'n'. (ARG_NO)
; Num_Type(n,LEFT) - Type left justified.
; Num_Type(n,NOCR) - Type without following newline.
; Num_Type(n,HEX) - Display in hex (always left justified).
; NT( n,HEX+NOMSG) - Suppress "0x" and ":"
; Num_Type(n,FILL) - Pad with "0" instead of spaces.
; Num_Type(n,FORCE)- Always display 10 columns.
; Num_Type(n,EXTRA)- Display extra padding if positive number.
; Following options are new, improved and different.
; When COUNT is used, no CRLF automatically issued.
; Can also be combined with the following:
; O_COUNT - required: LSB = field width;
; middle 2 bytes reserved for floating point;
; upper byte: optional error char ('*' override).
; O_APPEND - display sign at end of number.
; O_FILL - pad with "0" instead of spaces.
; Note: currently same as REVERSE.
; O_FORCE - display '+' instead of ' ' for positive numbers.
; O_SIMPLE - treat as unsigned (%u, in "c").
; O_HEX - display in hex (always unsigned).
; O_FLOAT - 'n' is id of numreg with IBM 360 style floating
; point number: #n=0xh3h2h1SX, where:
; h1 = most significant hex digit;
; S is the sign bit;
; X is the exponent biased on 64. (Powers of
; 16). Typically 0x4n (pos) and 0xCn (neg).
; O_EXTRA - IBM-style double precision floating point number.
; Combined with O_FLOAT; redefines old-style usage.
; numreg[n] and numreg[n+1] are double precision:
; #n=0xh3h2h1SX; #n+1= 0xh7h6h5h4.
; O_EVAL - Evaluate from *EDTPTR ('n' is dummy). Currently
; with O_FLOAT only.
; O_SUPPRESS - suppress padding (with O_LEFT only).
; Note: do not use "NOCR" with COUNT; no CRLF is issued anyway and NOCR
; is the same as SUPPRESS which is already being used.
Yes, these commands can convert from floating point numbers to ASCII, but I'm not ready to document it now.