Post Reply 
STRING Help?
05-13-2023, 05:24 PM (This post was last modified: 05-13-2023 05:28 PM by toml_12953.)
Post: #1
STRING Help?
I'm trying to use the STRING function to print a monospaced string. I've read the manual over and over. It could really use more examples! When I try the following, I get Invalid input but I can't see what's wrong. I don't want anything fancy, I just want to print using the current parameters except in a monospaced font. Can someone point me in the right direction?

Code:
EXPORT Monospace(X)
BEGIN
  PRINT(STRING(X,0,-1,-1,{50,10,0,0,1}));
END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
05-13-2023, 05:46 PM
Post: #2
RE: STRING Help?
Font size has to be between 0 and 7, you have 10. This works:

PRINT(STRING((1/3),0,-1,-1,{50,7,0,0,1}))

and prints 0.3

-road
Find all posts by this user
Quote this message in a reply
05-13-2023, 06:00 PM
Post: #3
RE: STRING Help?
(05-13-2023 05:46 PM)roadrunner Wrote:  Font size has to be between 0 and 7, you have 10. This works:

PRINT(STRING((1/3),0,-1,-1,{50,7,0,0,1}))

and prints 0.3

-road

Thanks! The manual I have says this on page 635:

"You can also specify the font size (10 to 22)" so it looked like the range is 10 - 22.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
05-13-2023, 06:12 PM
Post: #4
RE: STRING Help?
(05-13-2023 06:00 PM)toml_12953 Wrote:  The manual I have says this on page 635:

"You can also specify the font size (10 to 22)" so it looked like the range is 10 - 22.

The calculator Help is generally more up-to-date than the manual.
For STRING it says:

Quote:Syntax:
STRING(Expression, [Mode], [Precision], [Separator or {Separator, ["[DecimalPoint[Exponent[NegativeSign]]]"], [DotZero]}], [SizeLimit or {SizeLimit, [FontSize], [Bold], [Italic], [Monospaced]}])

Evaluates Expression and returns the result as a string.

The Mode, Precision, and Separator parameters specify how numbers are displayed.

If Mode is specified, it is:
0: Use current setting
1: Standard
2: Fixed
3: Scientific
4: Engineering
5: Floating
6: Rounded

Add 7 to this value to specify proper fraction mode and 14 for mixed fraction mode.

Precision is either -1 for current settings or 0 to 12.

Separator can be a number. -1 means use default, 0 to 10 correspond to the 11 built-in digit grouping choices available in home settings.
OR
Separator can be a string containing a set of digits and separators. The last digit is assumed to be the one just before the decimal point.

"[DecimalPoint[Exponent[NegativeSign]]]" is a string of 0 to 3 characters. The first one will be used for the decimal point, the second for the exponent and the last one for the negative sign.

If DotZero is non-zero, then numbers between -1 and 1 are displayed without a leading zero (for example, .1 instead of 0.1)

If SizeLimit is specified, the command will attempt to generate a string that fits in the given number of pixels. FontSize is used along with Bold, Italic, and Monospaced (if their value is non-zero) to estimate the maximum string length that will fit.

The values for FontSize are:
0=current font (default)
1=font 10
2=font 12 (Small)
3=font 14 (Medium)
4=font 16 (Large)
5=font 18
6=font 20
7=font 22


Examples:

Current number format setting Standard:
STRING(3*π) → "9.42477796077"

Number format Fixed, 4 decimal places:
STRING(3*π,2,4) → "9.4248"
Find all posts by this user
Quote this message in a reply
05-14-2023, 11:04 AM
Post: #5
RE: STRING Help?
Do the bold, italic and monospaced switches actually work? I don't see a difference when I turn them on or off.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
05-14-2023, 12:34 PM
Post: #6
RE: STRING Help?
(05-14-2023 11:04 AM)toml_12953 Wrote:  Do the bold, italic and monospaced switches actually work? I don't see a difference when I turn them on or off.

Yes, they do work. However this is primarily for calculating the sizing of the string advance (hence you need to take into account the glyph changes for complete accuracy). If you then feed the same printing format into the print function, you will end up seeing the printed output reflect the style.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
05-14-2023, 06:23 PM
Post: #7
RE: STRING Help?
(05-14-2023 12:34 PM)Tim Wessman Wrote:  
(05-14-2023 11:04 AM)toml_12953 Wrote:  Do the bold, italic and monospaced switches actually work? I don't see a difference when I turn them on or off.

Yes, they do work. However this is primarily for calculating the sizing of the string advance (hence you need to take into account the glyph changes for complete accuracy). If you then feed the same printing format into the print function, you will end up seeing the printed output reflect the style.

Could you give a small example such as I did?

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)