Purpose |
Format one or more
| ||||||||||||||||||||||||||||||||||||
Syntax |
sResult$ = USING$(fmtmask$, expr [, expr [, ...]]) | ||||||||||||||||||||||||||||||||||||
Remarks |
The rules of formatting are based upon the PRINT USING statement supported in many DOS versions of BASIC, including PowerBASIC for DOS. However, since it is implemented as a function, it allows far more versatility in that it is not necessary to output a value to gain the benefit of this unique functionality. Also, USING$ offers a wider range of applications than FORMAT$ because it can format both numeric and string expressions, and can take multiple arguments. | ||||||||||||||||||||||||||||||||||||
fmtmask$ |
A string expression, string variable or string literal consisting of format characters that will determine how the complete expression should be formatted. This expression is termed the mask. There may be as many format masks in fmtmask$, arranged in the same order as the expr arguments are specified. See the examples below for more information. | ||||||||||||||||||||||||||||||||||||
expr |
A string or numeric expression, variable, or literal
value to be formatted. The mask characters available depend on whether
expr is a string or numeric.
| ||||||||||||||||||||||||||||||||||||
Restrictions |
The returned string is limited to an absolute length limit of 1024 bytes. By specifying a single mask in fmtmask$, all expr arguments are subjected to the single mask. See the examples below. If there are fewer expr arguments than matching format masks in fmtmask$, parsing of the fmtmask$ halts after the last referenced mask position, and subsequent characters in fmtmask$ are ignored. This is consistent with the behavior of PRINT USING$ in PB/DOS. If a numeric argument overflows its mask (i.e., there are more digits than digit positions), the resulting string will occupy as many spaces as needed to represent the number. In such cases, PB/DOS includes a leading "%" symbol to indicate the mask overflow; however, PowerBASIC for Windows does not return the additional "%" overflow character. The semicolon (;) and zero (0) characters are reserved for future use, so it would be prudent to escape such literal characters in USING$ masks to maintain future compatibility. | ||||||||||||||||||||||||||||||||||||
See also |
|||||||||||||||||||||||||||||||||||||
Example |
a$ = USING$("!", "abc") ' returns "a"
a$ = USING$("You owe $$#,.##", 12345.67@) ' returns "You owe $12,345.67
DIM p AS BYTE PTR HOST ADDR "localhost" TO ip& p = VARPTR(ip&) a$ = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3]) ' returns "127.0.0.1"
a$ = USING$("&=#.##############", "Pi", ATN(1)*4) ' returns "Pi=3.14159265358979"
a$ = USING$("!", "AX", "BX", "CX") ' returns "ABC"
a$ = USING$("$#.##_,", 1,20,300,4) ' returns "$1.00,$20.00,$300.00,$4.00,"
a$ = USING$("$*=#####.##_,",1,20) ' returns "$======1.00,$=====20.00," |