Qbasicnews.com
August 25, 2019, 11:25:06 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
  Print  
Author Topic: Challenge: International version of PRINT USING  (Read 7498 times)
Moneo
Na_th_an
*****
Posts: 1971


« on: May 09, 2004, 04:45:08 PM »

It just dawned on me that the PRINT USING statement is designed only for USA formatted numbers; that is, using the decimal point to delimit fractional values, and commas to separate thousands. Also, the statement only uses the dollar sign.

Other countries use a comma instead of a decimal point to delimit fractional values, periods (decimal points) to separate thousands, and their own currency symbol instead of the dollar sign.

CHALLENGE: Write a replacement function, sub-program, or subroutine that allows for specifying:

1) The delimiter (comma or decimal point) for fractional values. Example: The number 123.45 in the USA is printed as 123.45 and in other countries (like Spain) as 123,45

2) The separator character for thousands.
Example: The number 12345 is printed as 12,345 in the USA and in other countries as 12.345

3) The currency symbol to use. Example: $ or

FORMATTING CHARACTERS: The formatstring for the PRINT USING specifies 12 formatting characters for formatting strings and numbers (check your manual). For this challenge we will only use the following formatting characters for numbers only:
(#) for each digit position.
(Specified delimiter for fractional values) decimal pt  or comma.
(+) causes sign of the number to be printed before the number.
(-) causes negative number to be printed with a trailing minus sign.
(**) Asterisk protection: causes leading spaces in numeric field to be filled with asterisks.
($$) Floating dollar sign: we will continue to use $$ to specify this feature, but it should actually print the currency symbol defined.
(**$) Floating dollar sign with asterisk protection. A combination of the two above.
(specified separator character for thousands) comma or decimal pt.

PLEASE: when you submit the code for your solutions, please preface the code with a brief explanation of your method or idea for the solution.

NOTE: There are several ways of doing this, some relatively simple, others very complicated. For the most part, I will not get into your code, I'll just compile it and test some results. I'll try to keep up with your entries.

I will request that the winner's code be posted in the tutorials section.
*****
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #1 on: May 11, 2004, 11:21:17 PM »

Hey some of you guys outside of the USA, I'm sure you must have encountered incompatibility problems with the PRINT USING statement in your country. Tell us about how you handled this problem. I can't believe you have a local-country, translated version of QB or QuickBASIC.
*****
Logged
SCM
Wandering Guru
***
Posts: 311



« Reply #2 on: May 13, 2004, 02:51:44 AM »

Moneo,

What character is supposed to be used for the Euro?  We're using a program that predates it by a couple of decades.  CHR$(238) looks close.
Logged

hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Moneo
Na_th_an
*****
Posts: 1971


« Reply #3 on: May 14, 2004, 12:33:55 AM »

SCM,

That's a really good question. I really don't know because I have a new keyboard which comes with the Euro symbol. That's how I printed it in point (3) above.

The symbol displays fine in Windows, but if you transfer the character to a text file to look at it with a hex editor in MSDOS, it converts the character to a capital French C, the one with the hook at the bottom.

Is there such a thing as a hex editor that runs in Windows?
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #4 on: May 14, 2004, 12:52:14 AM »

My favorite is Hex Workshop
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #5 on: May 15, 2004, 08:24:47 PM »

Thanks, Plasma, checked out the Hex Workshop site and it sounds great except for the $50 price. A bit much for the once in a blue moon that I might need it. But thanks anyway.

BTW, if you have it, please tell SCM what the hex (or decimal) character code is for the following Euro symbol:
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #6 on: May 16, 2004, 12:42:31 AM »

The Euro is D5h (213) on codepage 858.
Logged
Jonathan Simpson
Forum Regular
**
Posts: 140



« Reply #7 on: May 16, 2004, 09:33:40 AM »

It's possible to modify characters in the ascii table... maybe thats an option to make the euro available.
Logged

onathan Simpson
Moneo
Na_th_an
*****
Posts: 1971


« Reply #8 on: May 18, 2004, 10:29:36 PM »

Hey you guys outside the USA where you use a comma instead of a decimal point.

Have you ever had problems with PRINT USING? Have any of you written any check printing, invoice or statement printing programs in your country and tried to use PRINT USING?

If this was not a problem, tell me how you did it.
*****
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #9 on: May 19, 2004, 01:48:16 AM »

I find it an interesting challenge, and I would enter if I had the time. It involves parsing and using FSMs, two things that I love... But I have 0 time Sad

As for having needed it, I have never. For business applications I've always used Visual Basic, in every assignment or job I've had running QB was a problem, and using Visual Basic is so easy that it hurts Tongue

Seriously, I think I never wrote "PRINT USING" in a proggie. In QB all I've done is games, scripting systems, DOS utils and interpreters.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Moneo
Na_th_an
*****
Posts: 1971


« Reply #10 on: May 21, 2004, 12:33:08 AM »

Nathan,

What's are FSM's?

If you've never used PRINT USING, then the vast majority of our QB friends here probably haven't used it either. Oh well.....
*****
Logged
SCM
Wandering Guru
***
Posts: 311



« Reply #11 on: May 21, 2004, 01:13:08 AM »

Some of us use it.  I just recently learned from another members code that you can format more than one data type within the same string.  That makes it pretty flexible.
Code:
j% = 10
Sum# = 3.83105945587#
PRINT USING "####) ##.######"; j%; Sum#

Output:
  10)  3.831059
I've thought about writing my own version from time to time, to have it do things I want it to do, but now is not a good time for me.  It would be nice to see someone take this on.
Logged

hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #12 on: May 21, 2004, 02:10:26 AM »

Quote from: "Moneo"
What's are FSM's?


Finite State Machines.
Logged

na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #13 on: May 21, 2004, 08:15:20 AM »

Quote from: "Moneo"
Nathan,

What's are FSM's?


Woah! Deja vu! Cheesy

http://forum.qbasicnews.com/viewtopic.php?t=4882&start=25

Wink

FSMs are very suited for interpreters. And many other things. I love them. They saved my life 2000 times.

A PRINT USING replacement would be extremely complex to code, so I have to admit it is a great idea for a challenge, 'cause I find it terribly challenging... If only I could put 20 minutes together...
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Moneo
Na_th_an
*****
Posts: 1971


« Reply #14 on: May 23, 2004, 01:23:42 AM »

Nathan,

Thanks for the flashback on the FSM issue.

To do a PRINT USING replacement is going to take you more than 20 minutes. There's too many tricky things like floating dollar sign, asterisk protection and negative sign on the right of the number.

The replacement routine of this challenge says to be able to specify (1) the decimal or comma delimeter (2) the comma or decimal separator for thousand (3) the currency symbol.

You don't need to write the entire PRINT USING logic to accomplish the above 3 steps. (This is a hint). The solution that I have in mind should take about 10 minutes to write and another 10 minutes to debug.
*****
*****
Logged
Pages: [1] 2
  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!