Qbasicnews.com
April 12, 2021, 07:09:09 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: Strange results in FB with PRINT USING.  (Read 10068 times)
Moneo
Na_th_an
*****
Posts: 1971


« on: July 30, 2005, 05:00:41 PM »

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?
*****
Logged
rpgfan3233
Ancient Guru
****
Posts: 617



« Reply #1 on: July 30, 2005, 05:48:03 PM »

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?wakka=KeyPgPrintusing
Logged

974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #2 on: July 30, 2005, 06:02:38 PM »

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 Cheesy

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!
Logged

Antoni
rpgfan3233
Ancient Guru
****
Posts: 617



« Reply #3 on: July 30, 2005, 06:12:49 PM »

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.
Logged

974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #4 on: July 30, 2005, 07:15:14 PM »

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.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #5 on: July 30, 2005, 08:42:19 PM »

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?
*****
Logged
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #6 on: July 30, 2005, 08:47:06 PM »

The wiki:
http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgPrintusing
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #7 on: July 30, 2005, 09:34:45 PM »

Quote from: "Jofers"


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.
*****
Logged
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #8 on: July 30, 2005, 09:42:23 PM »

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.
Logged
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #9 on: July 30, 2005, 09:49:28 PM »

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. Smiley )
Logged
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #10 on: July 30, 2005, 10:22:24 PM »

http://qbasicnews.com/qboho/qckadvr@l816d.shtml

QB Online Help Online, the first useful thing I ever put on the internet.  View in IE if it looks funky (Netscape 4 was a lost cause at the time of creation).
Logged
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #11 on: July 30, 2005, 10:41:31 PM »

That looks halfway decent in Opera. Smiley I'll see if I can implement a few more of those; thanks for the link (should've thought of that myself... Cheesy ).
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #12 on: July 31, 2005, 07:34:46 AM »

See if you can do a STRING USING too..Cheesy
Logged

Antoni
Moneo
Na_th_an
*****
Posts: 1971


« Reply #13 on: July 31, 2005, 07:56:08 PM »

Quote from: "DrV"
That looks halfway decent in Opera. Smiley I'll see if I can implement a few more of those; thanks for the link (should've thought of that myself... Cheesy ).

I just did a visual check of the Online Help for Print Using against my Quickbasic manual. The only difference is the following from the OnLine Help:
Code:

 \\     \\    Prints 2 + n characters from the string, where n is the  
             number of spaces between the two backslashes.... etc.

The Quickbasic manual has:
 \     \    Prints 2 + n characters from the string, where n is the  
             number of spaces between the two backslashes.... etc.


Other than that, they are identical.

IMHO you guys that are working on FB are faced with a dilema regarding the Print Using. I see 3 options:

1) Select a subset of the special formatting characters, perhaps the 5 that are now defined, or maybe a few more, and get them to work the same as in QB. In the Print Using documentation, specify the other formatting characters as not supported.

2) Implement all the formatting characters to work as in QB. This is by far the most difficult option.

3) Declare Print Using as not supported, making reference to the available printf and sprintf functions.
*****
Logged
rpgfan3233
Ancient Guru
****
Posts: 617



« Reply #14 on: August 01, 2005, 12:41:08 AM »

Quote from: "Moneo"
I just did a visual check of the Online Help for Print Using against my Quickbasic manual. The only difference is the following from the OnLine Help:
Code:

 \\     \\    Prints 2 + n characters from the string, where n is the  
             number of spaces between the two backslashes.... etc.

The Quickbasic manual has:
 \     \    Prints 2 + n characters from the string, where n is the  
             number of spaces between the two backslashes.... etc.

The "\\" was probably supposed to be an escape sequence to just use the "\", but it didn't work correctly or something. It should be just "\".
Logged

974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!