Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strange results in FB with PRINT USING.
#1
DIM X AS SINGLE
OPEN "TEST.FIL" FOR OUTPUT AS #1

X = 1234.5
PRINT #2,USING "####.#-";X

For the above, the result on the file was: 1234.5-
Why the negative sign?
Same code in QB gives result of: 1234.5

X = -1234.5
PRINT #2,USING "####.#-";X

For the above, the result on the file was: -1234.5-
Why the negative sign in front and back?
Same code in QB gives result of: 1234.5-

Has something changed in FB for the Print Using?
*****
Reply
#2
It appears that FB is following its "All other chars or misplaced format chars are interpreted as regular chars and printed."

The "-" character is not listed in the table of formatting characters for the USING keyword in FB's online documentation.

http://www.freebasic.net/wiki/wikka.php?...Printusing
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply
#3
I did that page on the online documentation from some guesswork , and I decided to be conservative. I see I was right at not including - as a control symbol Big Grin

It seems v!c implemented only the most used controls, considering PRINT USING an oddity of the past... I have been asking in vain for a STRING USING (like c's sprintf) for months.

Perhaps we should design a library of formatting functions. A theme for one of your contests, Moneo!
Antoni
Reply
#4
I have a question while we're on the subject of PRINT USING oddities. Why does placing '$' before a digit place truncate a number with decimal places, despite including the decimal point in the format?

Code:
PRINT USING "$###.##"; 65.55
SLEEP

I'm assuming the rounding method used is the same as FIX() since it seems to be just truncated.

The "$$" formatting marker works however. It works the same as in QB as far as I know.
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply
#5
V1c hasn't added STRING USING, and probably did a half-assed job on PRINT USING because "printf" and "sprintf" are available by including crt.bi.

I do not know all the behavior of PRINT USING, but the c source for the runtime library is at freebasic.net, you might want to take a crack at updating it (couldn't hurt).

Of course, a runtime library routine for STRING USING could be done, but to add the keywords I guess you'd have to edit the parser's list of funky keyword sets.
Reply
#6
Sorry guys, but I don't quite understand all your explanations.

Should I take it to mean that the PRINT USING as implemented in Freebasic does not work the same as in QB/QuickBasic?

The description of the 11 special formatting characters for numbers, defined for Print Using, fills two pages in my QuickBasic manual. Since some of these may work differently in FB, where can I find a description of which are supported and how they work in FB?
*****
Reply
#7
The wiki:
http://www.freebasic.net/wiki/wikka.php?...Printusing
Reply
#8
Quote:The wiki:
http://www.freebasic.net/wiki/wikka.php?...Printusing

Nice documentation, for a beginning.
Only 5 of the 11 format characters in QB are offered. All 5 format characters have some differences from QB in their functionality.

Is there a chance that the additional format characters will be added later?

The section called "Differences from QB" has nothing in it.
*****
Reply
#9
I don't know. The C source code from the runtime library can be downloaded for free from http://www.freebasic.net, anyone willing to patch it should do so. I doubt v1ctor or one of the other developers will, because they added PRINT USING just to be backwords compatible.

Also, anyone is free to edit the documentation, as it is a wiki.
Reply
#10
If you could describe how the format characters are supposed to work, I could try my hand at implementing them; I personally have never had any use for PRINT USING, but it wouldn't hurt to have QB compatability. (However, the source file is already 580 lines long, so it won't be a walk in the park. Smile )
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)