QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: zaadstra on December 29, 2020, 05:51:27 pm

Title: PRINT USING for non US numbers
Post by: zaadstra on December 29, 2020, 05:51:27 pm
Hi,

I wonder if it is possible to setup PRINT USING to display (large) numbers, separated with points instead of comma's.  This is common in EU and possibly other areas.

Wiki http://www.qb64.org/wiki/PRINT_USING (http://www.qb64.org/wiki/PRINT_USING) says:
  ,.    Comma to left of decimal point, prints a comma every 3 used # digit places left of the decimal point.

This gives me 324,653,221.  if programmed with PRINT USING "##############,."; a  (and I don't need decimals here).
Stripping to PRINT USING "##############,"; a      (undocumented on wiki) makes it even better to  324,653,221

But PRINT USING "##############."; a    doesn't do the trick.

I like to see my number as 324.653.221 with PRINT USING and preferrably without coding that myself in a Function ;-)

Is this possible?

Title: Re: PRINT USING for non US numbers
Post by: OldMoses on December 29, 2020, 07:40:37 pm
I'm not really familiar with PRINT USING templates. I've used them, but they usually devil me terribly. Maybe someone else knows more, but I think it's not generally possible. How would one tell the difference between 1,000,000.321 and 1.000.000.321? Is it a million and three decimal places or a tad over a billion? Sounds like a good way to get something wrong by orders of magnitude. Of course, if it's understood that one is only working with integers then I suppose it would be fine.

In the spirit of addressing the problem I offer the following...

Code: QB64: [Select]
  1.  
  2.     CLS
  3.     INPUT "enter a number for point conversion ", a##
  4.     Point_Number a##
  5.     PRINT "Space to continue"
  6.     SLEEP
  7.  
  8. SUB Point_Number (var AS _FLOAT)
  9.  
  10.     x$ = _TRIM$(STR$(var))
  11.     full% = LEN(x$)
  12.     dec_point% = INSTR(x$, ".")
  13.     IF dec_point% = 0 THEN lngth% = full% ELSE lngth% = dec_point% - 1
  14.     FOR x = 1 TO lngth%
  15.         IF ((lngth% + 1 - x) / 3 = INT((lngth% + 1 - x) / 3)) AND x <> 1 THEN
  16.             y$ = y$ + "."
  17.         END IF
  18.         y$ = y$ + MID$(x$, x, 1)
  19.     NEXT x
  20.     IF dec_point% <> 0 THEN y$ = y$ + MID$(x$, dec_point%)
  21.     PRINT y$
  22.  
  23.  
Title: Re: PRINT USING for non US numbers
Post by: luke on December 29, 2020, 08:15:10 pm
Unfortunately PRINT USING is fairly American, and doesn't really know about internationalisation.

Likely you'll have to write a routine yourself (or even better, wait a few days and someone will likely come along with one for you).
Title: Re: PRINT USING for non US numbers
Post by: TempodiBasic on January 01, 2021, 03:10:07 pm
Hi zaadstra
your homework is:
print an integer number using the point for dividing the thousand multiple at the place of the comma.
PRINT USING let format the output of the number but it divides the thousand multiple using the comma.

Here one of the thousand possible solutions
Code: QB64: [Select]
  1.  
  2. i1 = -23200
  3. i2 = 12345678901
  4. PRINT "   Input        Output"
  5. PRINT i1, IntPrintUsing$(STR$(i1))
  6. PRINT i2, IntPrintUsing$(STR$(i2))
  7.  
  8. FUNCTION IntPrintUsing$ (Toprint AS STRING)
  9.     DIM in AS STRING, tmp AS STRING, index AS INTEGER, cont AS INTEGER
  10.     Toprint = _TRIM$(Toprint)
  11.     IF INSTR(Toprint, "-") THEN in = MID$(Toprint, INSTR(Toprint, "-") + 1, LEN(Toprint) - INSTR(Toprint, "-")) ELSE in = Toprint
  12.     cont = 0: index = 0
  13.     WHILE cont < LEN(in)
  14.         IF index + 3 < LEN(in) THEN
  15.             index = index + 3
  16.         ELSE
  17.             index = LEN(in) - index
  18.         END IF
  19.         cont = cont + 3
  20.         IF index > 2 THEN tmp = "." + MID$(in, 1 + LEN(in) - index, 3) + tmp ELSE tmp = MID$(in, 1, index) + tmp
  21.     WEND
  22.     in = tmp
  23.     IF INSTR(Toprint, "-") THEN in = "-" + in
  24.     IntPrintUsing$ = in

this can be optimized to save time (for example storing in a variable the result of LEN(in) instead of calculating each time this same result)

Good Enjoying  with programming
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 01, 2021, 06:42:18 pm
Unfortunately PRINT USING is fairly American, and doesn't really know about internationalisation.

Likely you'll have to write a routine yourself (or even better, wait a few days and someone will likely come along with one for you).

Ha I was expecting @RhoSigma to come along ;-))  must be on Holidays.



Hi zaadstra
your homework is:
print an integer number using the point for dividing the thousand multiple at the place of the comma.
PRINT USING let format the output of the number but it divides the thousand multiple using the comma.

Here one of the thousand possible solutions
Code: QB64: [Select]
  1.  
  2. i1 = -23200
  3. i2 = 12345678901
  4. PRINT "   Input        Output"
  5. PRINT i1, IntPrintUsing$(STR$(i1))
  6. PRINT i2, IntPrintUsing$(STR$(i2))
  7.  
  8. FUNCTION IntPrintUsing$ (Toprint AS STRING)
  9.     DIM in AS STRING, tmp AS STRING, index AS INTEGER, cont AS INTEGER
  10.     Toprint = _TRIM$(Toprint)
  11.     IF INSTR(Toprint, "-") THEN in = MID$(Toprint, INSTR(Toprint, "-") + 1, LEN(Toprint) - INSTR(Toprint, "-")) ELSE in = Toprint
  12.     cont = 0: index = 0
  13.     WHILE cont < LEN(in)
  14.         IF index + 3 < LEN(in) THEN
  15.             index = index + 3
  16.         ELSE
  17.             index = LEN(in) - index
  18.         END IF
  19.         cont = cont + 3
  20.         IF index > 2 THEN tmp = "." + MID$(in, 1 + LEN(in) - index, 3) + tmp ELSE tmp = MID$(in, 1, index) + tmp
  21.     WEND
  22.     in = tmp
  23.     IF INSTR(Toprint, "-") THEN in = "-" + in
  24.     IntPrintUsing$ = in

this can be optimized to save time (for example storing in a variable the result of LEN(in) instead of calculating each time this same result)

Good Enjoying  with programming

@TempodiBasic

Try more numbers for your Function:
Code: QB64: [Select]
  1.  
  2.     PRINT
  3.     INPUT "Enter an Integer to convert > "; test
  4.     PRINT IntPrintUsing$(STR$(test))
  5. LOOP UNTIL test = 0
  6.  
  7. FUNCTION IntPrintUsing$ (Toprint AS STRING)
  8.     DIM in AS STRING, tmp AS STRING, index AS INTEGER, cont AS INTEGER
  9.     Toprint = _TRIM$(Toprint)
  10.     IF INSTR(Toprint, "-") THEN in = MID$(Toprint, INSTR(Toprint, "-") + 1, LEN(Toprint) - INSTR(Toprint, "-")) ELSE in = Toprint
  11.     cont = 0: index = 0
  12.     WHILE cont < LEN(in)
  13.         IF index + 3 < LEN(in) THEN
  14.             index = index + 3
  15.         ELSE
  16.             index = LEN(in) - index
  17.         END IF
  18.         cont = cont + 3
  19.         IF index > 2 THEN tmp = "." + MID$(in, 1 + LEN(in) - index, 3) + tmp ELSE tmp = MID$(in, 1, index) + tmp
  20.     WEND
  21.     in = tmp
  22.     IF INSTR(Toprint, "-") THEN in = "-" + in
  23.     IntPrintUsing$ = in
  24.  
  25.  

I am not liking how 999 and -999 are looking, how about you?
Title: Re: PRINT USING for non US numbers
Post by: TempodiBasic on January 01, 2021, 08:26:58 pm
Hi Bplus
Thanks to find a bug to that function!
It didn't manage rightly the number with digits multiple of 3!

Now it seems that it works.

Give a try to this fix.
Code: QB64: [Select]
  1.  
  2. i1 = -23200
  3. i2 = 12345678901
  4. i3 = 799444
  5. i4 = -999
  6. i5 = -111222333
  7. PRINT "   Input        Output"
  8. PRINT i1, IntPrintUsing$(STR$(i1))
  9. PRINT i2, IntPrintUsing$(STR$(i2))
  10. PRINT i3, IntPrintUsing$(STR$(i3))
  11. PRINT i4, IntPrintUsing$(STR$(i4))
  12. PRINT i5, IntPrintUsing$(STR$(i5))
  13.  
  14. FUNCTION IntPrintUsing$ (Toprint AS STRING)
  15.     DIM in AS STRING, tmp AS STRING, index AS INTEGER, cont AS INTEGER
  16.     Toprint = _TRIM$(Toprint)
  17.     IF INSTR(Toprint, "-") THEN in = MID$(Toprint, INSTR(Toprint, "-") + 1, LEN(Toprint) - INSTR(Toprint, "-")) ELSE in = Toprint
  18.     cont = 0: index = 0
  19.     WHILE cont < LEN(in)
  20.         IF index + 3 <= LEN(in) THEN
  21.             index = index + 3
  22.         ELSE
  23.             index = LEN(in) - index
  24.         END IF
  25.         cont = cont + 3
  26.         IF index > 2 THEN tmp = "." + MID$(in, 1 + LEN(in) - index, 3) + tmp ELSE tmp = MID$(in, 1, index) + tmp
  27.     WEND
  28.     IF LEN(in) - cont = 0 THEN tmp = RIGHT$(tmp, LEN(tmp) - INSTR(tmp, "."))
  29.     in = tmp
  30.     IF INSTR(Toprint, "-") THEN in = "-" + in
  31.     IntPrintUsing$ = in

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: PRINT USING for non US numbers
Post by: RhoSigma on January 01, 2021, 08:29:20 pm
Ha I was expecting @RhoSigma to come along ;-))  must be on Holidays.

Funny thing, I was just about releasing a bigger update to my IndexFormat() function before the year's end, when this topic popped up, which made me rethink things before the release. So still give me a day or two to finish things and you'll not only able to flip the comma/dot notation, but also to exchange the $ currency sign. Also a feature request on GitHub asks for the ability to group hex/bin/oct outputs, which can be achieved with the new IndexFormat() function too, so stay tuned....
Title: Re: PRINT USING for non US numbers
Post by: TempodiBasic on January 01, 2021, 09:30:35 pm
Waiting the sooner RhoSigma developments
Here another way to do the same work of the first : just use the point instead of comma for thousands multiple on printing on the screen an integer digit.


Code: QB64: [Select]
  1.  
  2. i1 = -23200
  3. i2 = 12345678901
  4. i3 = 799444
  5. i4 = -999
  6. i5 = -11122233
  7. i6 = -111222333
  8. PRINT "   Input        Output   "
  9. PRINT i1, IntPrintUsing$(STR$(i1))
  10. PRINT i2, IntPrintUsing$(STR$(i2))
  11. PRINT i3, IntPrintUsing$(STR$(i3))
  12. PRINT i4, IntPrintUsing$(STR$(i4))
  13. PRINT i5, IntPrintUsing$(STR$(i5))
  14. PRINT i6, IntPrintUsing$(STR$(i6))
  15. PRINT "----Input--------Output---"
  16. PRINT i1, IntPrintUsing2$(STR$(i1))
  17. PRINT i2, IntPrintUsing2$(STR$(i2))
  18. PRINT i3, IntPrintUsing2$(STR$(i3))
  19. PRINT i4, IntPrintUsing2$(STR$(i4))
  20. PRINT i5, IntPrintUsing2$(STR$(i5))
  21. PRINT i6, IntPrintUsing2$(STR$(i6))
  22.  
  23. FUNCTION IntPrintUsing$ (Toprint AS STRING)
  24.     DIM in AS STRING, tmp AS STRING, index AS INTEGER, cont AS INTEGER
  25.     Toprint = _TRIM$(Toprint)
  26.     IF INSTR(Toprint, "-") THEN in = MID$(Toprint, INSTR(Toprint, "-") + 1, LEN(Toprint) - INSTR(Toprint, "-")) ELSE in = Toprint
  27.     cont = 0: index = 0
  28.     WHILE cont < LEN(in)
  29.         IF index + 3 <= LEN(in) THEN
  30.             index = index + 3
  31.         ELSE
  32.             index = LEN(in) - index
  33.         END IF
  34.         cont = cont + 3
  35.         IF index > 2 THEN tmp = "." + MID$(in, 1 + LEN(in) - index, 3) + tmp ELSE tmp = MID$(in, 1, index) + tmp
  36.     WEND
  37.     IF LEN(in) - cont = 0 THEN tmp = RIGHT$(tmp, LEN(tmp) - INSTR(tmp, "."))
  38.     in = tmp
  39.     IF INSTR(Toprint, "-") THEN in = "-" + in
  40.     IntPrintUsing$ = in
  41.  
  42. FUNCTION IntPrintUsing2$ (Toprint AS STRING)
  43.     DIM l AS INTEGER, in AS STRING, Tmp AS STRING, Start AS INTEGER, cont AS INTEGER
  44.     Toprint = _TRIM$(Toprint)
  45.     IF INSTR(Toprint, "-") THEN in = MID$(Toprint, INSTR(Toprint, "-") + 1, LEN(Toprint) - INSTR(Toprint, "-")) ELSE in = Toprint
  46.     l = LEN(in)
  47.     IF l MOD 3 = 0 THEN
  48.         Start = 3
  49.         cont = 1
  50.     ELSE
  51.         Start = l MOD 3
  52.         cont = 0
  53.     END IF
  54.     Tmp = MID$(in, 1, Start)
  55.  
  56.     WHILE cont < l - Start
  57.         cont = cont + 3
  58.         Tmp = Tmp + "." + MID$(in, cont, 3)
  59.     WEND
  60.     IF INSTR(Toprint, "-") THEN Tmp = "-" + Tmp
  61.     IntPrintUsing2$ = Tmp
Thanks to try
Maybe it is possible to extend the function to Single and Double numbers...
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 01, 2021, 10:04:20 pm
@TempodiBasic  Ah yes the fix looks good but I like the idea of your 2nd approach, specially for real numbers AKA floats AKA having digits to the right of decimal or is it comma now hahaha!

ie do it the American way with PRINT USING then swap . for , and vice versa but save place of decimal first and do commas to dots then at place of decimal put the comma.
Title: Re: PRINT USING for non US numbers
Post by: zaadstra on January 02, 2021, 07:06:01 am
Hi guys,

Thanks for all the thinking and even solutions!  I'd never thought a question like this would generate so many solutions :-)

A I noticed the American bias (also in character sets I have to do quite some tricks),  this normally isn't a problem. I was just hoping that in a 'next' version of QB64 the print using options will be added for the 3 digit groups and the decimal comma,  or only the 3 digit groups (like ,. and . in print using).
Print Using indeed has it's quirks but when it is tamed then it solves quite some formatting stuff for you.

Meanwhile, I had written my own function for this,  and funny enough, again another approach like all pieces of code above are different:
To simulate Print using with it's column formatting, I added a column width with parameter 'printlen' and have the number aligned to the right.

Code: QB64: [Select]
  1. PRINT #99, "Matched  :"; PrintNiceRightAlign$(totalbytes1, 16); PrintNiceRightAlign$(totalbytes2, 16)
  2.  
  3. FUNCTION PrintNiceRightAlign$ (printnu&&, printlen)
  4.    ' Parameters: number to print, total character length to be filled
  5.    x$ = LTRIM$(STR$(printnu&&))
  6.    printnu$ = ""
  7.  
  8.    FOR i = LEN(x$) TO 1 STEP -1
  9.       printnu$ = printnu$ + MID$(x$, LEN(x$) - i + 1, 1)
  10.       IF ((i - 1) MOD 3 = 0) AND i <> 1 THEN printnu$ = printnu$ + "."
  11.    NEXT
  12.  
  13.    PrintNiceRightAlign$ = RIGHT$(SPACE$(printlen) + printnu$, printlen)
  14.  
  15. Matched  :   4.574.562.555   4.574.562.555
  16.  
Title: Re: PRINT USING for non US numbers
Post by: Mad Axeman on January 02, 2021, 12:14:10 pm
A I noticed the American bias

It's not just in the USA that a comma separator is used. We use it here in the UK too. Just out of interest, what country are you in?
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 02, 2021, 12:42:41 pm
Code: QB64: [Select]
  1.  
  2.     PRINT
  3.     INPUT "Enter an Integer to convert > "; test
  4.     PRINT PrintNiceRightAlign$(test, 20)
  5. LOOP UNTIL test = 0
  6.  
  7.  
  8. FUNCTION PrintNiceRightAlign$ (printnu&&, printlen)
  9.     ' Parameters: number to print, total character length to be filled
  10.     x$ = LTRIM$(STR$(printnu&&))
  11.     printnu$ = ""
  12.  
  13.     FOR i = LEN(x$) TO 1 STEP -1
  14.         printnu$ = printnu$ + MID$(x$, LEN(x$) - i + 1, 1)
  15.         IF ((i - 1) MOD 3 = 0) AND i <> 1 THEN printnu$ = printnu$ + "."
  16.     NEXT
  17.  
  18.     PrintNiceRightAlign$ = RIGHT$(SPACE$(printlen) + printnu$, printlen)
  19.  
  20.  
  21.  

Tested and I think fails on neg numbers:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

But is true you don't need $ for string constants or other suffix for other constants.
Title: Re: PRINT USING for non US numbers
Post by: zaadstra on January 02, 2021, 12:52:13 pm
It's not just in the USA that a comma separator is used. We use it here in the UK too. Just out of interest, what country are you in?
I'm in The Netherlands.  (hi neigbour!)

Now out of curiosity, which regions are using what, I did some reading: https://en.wikipedia.org/wiki/Decimal_separator (https://en.wikipedia.org/wiki/Decimal_separator)
We seem to owe our system to the Romans :-)
I'm not sure if there is a relation to the use of the imperial system of weights and measures in a country.
Title: Re: PRINT USING for non US numbers
Post by: zaadstra on January 02, 2021, 01:01:07 pm


Tested and I think fails on neg numbers:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

But is true you don't need $ for string constants or other suffix for other constants.

That is very much possible!  But as my byte counter only produce positive numbers, I have no issue with that.
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 02, 2021, 02:05:08 pm
EDIT: oops wrong post
Title: Re: PRINT USING for non US numbers
Post by: SMcNeill on January 02, 2021, 06:20:16 pm
Wouldn't an easy solution here be to just print to a temp screen, read the output into a string, and then swap the periods and commas?

Here's a format$ routine that I worked up in the past.  All it needs is to swap periods for commas, correct?

Code: QB64: [Select]
  1.  PRINT format$("###.###", "123.456789")
  2. PRINT format$("###,.##", "123456789.987654321")
  3.  
  4.  
  5. FUNCTION format$ (template AS STRING, text AS STRING)
  6.     d = _DEST: s = _SOURCE
  7.     n = _NEWIMAGE(80, 80, 0)
  8.     _DEST n: _SOURCE n
  9.     PRINT USING template; VAL(text)
  10.     FOR i = 1 TO 79
  11.         t$ = t$ + CHR$(SCREEN(1, i))
  12.     NEXT
  13.     IF LEFT$(t$,1) = “%” THEN t$ = MID$(t$,2)
  14.     format$ = t$
  15.     _DEST d: _SOURCE s
  16.     _FREEIMAGE n
Title: Re: PRINT USING for non US numbers
Post by: RhoSigma on January 02, 2021, 07:44:45 pm
Here's the new IndexFomat$() function, which I've mentioned earlier:
https://www.qb64.org/forum/index.php?topic=2932.0
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 02, 2021, 08:09:00 pm
Wouldn't an easy solution here be to just print to a temp screen, read the output into a string, and then swap the periods and commas?

Here's a format$ routine that I worked up in the past.  All it needs is to swap periods for commas, correct?

Code: QB64: [Select]
  1.  PRINT format$("###.###", "123.456789")
  2. PRINT format$("###,.##", "123456789.987654321")
  3.  
  4.  
  5. FUNCTION format$ (template AS STRING, text AS STRING)
  6.     d = _DEST: s = _SOURCE
  7.     n = _NEWIMAGE(80, 80, 0)
  8.     _DEST n: _SOURCE n
  9.     PRINT USING template; VAL(text)
  10.     FOR i = 1 TO 79
  11.         t$ = t$ + CHR$(SCREEN(1, i))
  12.     NEXT
  13.     IF LEFT$(t$,1) = “%” THEN t$ = MID$(t$,2)
  14.     format$ = t$
  15.     _DEST d: _SOURCE s
  16.     _FREEIMAGE n


Oh Steve added code to his post since I last looked. In meantime I worked up complete conversion starting with Fellippe's format$ function which is a little buggy, fixed the ones that started with comma but starting with zero's is more work!
Code: QB64: [Select]
  1. _TITLE "Format$ Function by Fellippe"
  2. ' ref  https://www.qb64.org/forum/index.php?topic=2932.msg121943#msg121943
  3.     r = RND < .5
  4.     IF r THEN x## = -1 * RND * 10 ^ INT(RND * 9) ELSE x## = RND * 10 ^ INT(RND * 9)
  5.     x## = x## + RND
  6.     PRINT swapAB$(format$("#####################,.####", x##), ",", ".")
  7.     SLEEP
  8.  
  9. FUNCTION format$ (template$, value##) 'this is not perfect some start with 0's
  10.     DIM tempImage&, prevDest&, prevSource&
  11.     DIM i AS INTEGER, result$
  12.  
  13.     tempImage& = _NEWIMAGE(LEN(template$) + 10, 1, 0)
  14.  
  15.     prevDest& = _DEST
  16.     prevSource& = _SOURCE
  17.     _DEST tempImage&
  18.     _SOURCE tempImage&
  19.  
  20.     PRINT USING template$; value##;
  21.     FOR i = 1 TO POS(0)
  22.         result$ = result$ + CHR$(SCREEN(1, i))
  23.     NEXT
  24.  
  25.     _DEST prevDest&
  26.     _SOURCE prevSource&
  27.     _FREEIMAGE tempImage&
  28.     IF LEFT$(result$, 1) = "," THEN result$ = RIGHT$(result$, LEN(result$) - 1) ' fix results that start with comma
  29.     format$ = result$
  30.  
  31. FUNCTION swapAB$ (s$, A$, B$)
  32.     FOR i = 1 TO LEN(s$)
  33.         IF MID$(s$, i, 1) = A$ THEN
  34.             build$ = build$ + B$
  35.         ELSEIF MID$(s$, i, 1) = B$ THEN
  36.             build$ = build$ + A$
  37.         ELSE
  38.             build$ = build$ + MID$(s$, i, 1)
  39.         END IF
  40.     NEXT
  41.     swapAB$ = build$
  42.  
  43.  
  44.  

Perhaps someone who actually needs this will fix remainder of bugs.
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 02, 2021, 08:31:04 pm
OK this is slightly better, no problem with 0 starts except where they should be, is it the string parameter?
I bet, because then you dont have to worry about the dang Number type!

Code: QB64: [Select]
  1. _TITLE "Format$ Function by Steve best so far 2021-01-02" ' b+ mod 2021-01-02
  2. ' ref https://www.qb64.org/forum/index.php?topic=3426.msg127488#msg127488
  3.     r = RND < .5
  4.     IF r THEN x## = -1 * RND * 10 ^ INT(RND * 9) ELSE x## = RND * 10 ^ INT(RND * 9)
  5.     x## = x## + RND
  6.     PRINT swapAB$(format$("#####################,.####", STR$(x##)), ",", ".")
  7.     SLEEP
  8.  
  9. FUNCTION format$ (template AS STRING, text AS STRING)
  10.     d = _DEST: s = _SOURCE
  11.     n = _NEWIMAGE(80, 80, 0)
  12.     _DEST n: _SOURCE n
  13.     PRINT USING template; VAL(text)
  14.     FOR i = 1 TO 79
  15.         t$ = t$ + CHR$(SCREEN(1, i))
  16.     NEXT
  17.     IF LEFT$(t$, 1) = "%" THEN t$ = MID$(t$, 2)
  18.     format$ = t$
  19.     _DEST d: _SOURCE s
  20.     _FREEIMAGE n
  21.  
  22. FUNCTION swapAB$ (s$, A$, B$)
  23.     FOR i = 1 TO LEN(s$)
  24.         IF MID$(s$, i, 1) = A$ THEN
  25.             build$ = build$ + B$
  26.         ELSEIF MID$(s$, i, 1) = B$ THEN
  27.             build$ = build$ + A$
  28.         ELSE
  29.             build$ = build$ + MID$(s$, i, 1)
  30.         END IF
  31.     NEXT
  32.     swapAB$ = build$
  33.  
  34.  
  35.  
Title: Re: PRINT USING for non US numbers
Post by: zaadstra on January 03, 2021, 04:55:13 am
Wouldn't an easy solution here be to just print to a temp screen, read the output into a string, and then swap the periods and commas?

Here's a format$ routine that I worked up in the past.  All it needs is to swap periods for commas, correct?


Thanks for showing this code, I wasn't familiar with the posibility of temp screens.  This may open a lot of new ideas as your examples shows.  I am going to play with this one!
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 03, 2021, 11:21:31 am
Thanks for showing this code, I wasn't familiar with the posibility of temp screens.  This may open a lot of new ideas as your examples shows.  I am going to play with this one!

Yes, an eye opener to me when I first came to QB64! from QB4.5 and early VB.

Screen 0 I think is the only one you can pull out characters on screen with SCREEN() Function.
Title: Re: PRINT USING for non US numbers
Post by: zaadstra on January 03, 2021, 11:33:37 am
It is the only screen I use,  graphics are not for me.
Only wishing it was somewhat more flexiible, bigger, resizeable, copy text from it (in win ctrl-C) ...

I'm still thinking I haven't seen all new goodies from QB64, compared to QB4.5! ;-)
Title: Re: PRINT USING for non US numbers
Post by: bplus on January 03, 2021, 12:58:09 pm
It is the only screen I use,  graphics are not for me.
Only wishing it was somewhat more flexiible, bigger, resizeable, copy text from it (in win ctrl-C) ...

I'm still thinking I haven't seen all new goodies from QB64, compared to QB4.5! ;-)

screen0 = 0 ' no graphics
anySize& = _NEWIMAGE(anyWidth, anyHeight, screen0 )

_dest anySize&  'private area for working on screen stuff or whatever

_dest 0 'back to the screen for display to user or can
Screen anySize&
Title: Re: PRINT USING for non US numbers
Post by: zaadstra on January 03, 2021, 02:53:06 pm
Amazing!  But so offtopic ;-)   I've got it working and will play around with this.
Title: Re: PRINT USING for non US numbers
Post by: SMcNeill on January 03, 2021, 02:54:40 pm
Amazing!  But so offtopic ;-)   I've got it working and will play around with this.

You might also try adding a $RESIZE command to your code.  ;)
Title: Re: PRINT USING for non US numbers
Post by: zaadstra on January 03, 2021, 03:04:42 pm
You might also try adding a $RESIZE command to your code.  ;)
Noted! :-)   I know my way around on the Wiki but do not always see the connection between the (new) commands.
Also, it sometimes takes some puzzling to see how the system 'thinks' (like with the screen and _dest commands). Before this I only discovered the Console as extra window, because of it's different properties (more shell window like, just like QB4.5).