Author Topic: Print Using  (Read 5556 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Print Using
« on: June 30, 2021, 04:26:52 pm »
Does anyone know how to simulate the Print Using command? I would like to know how the command formats the output based on the 'pattern' given by the command. Just curious.. If this is too trivial, just let me know. I will not be offended. But, remember, your avatar and your embedded GPS information will be added to my black list... Moo Ha Ha....
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Print Using
« Reply #1 on: June 30, 2021, 05:47:57 pm »
Moo Ha Ha....

Is that your impression of a cow laughing?  MuHaha?!!

Somewhere here on the forums, I have a FUNCTION Format$ which can be used to simulate PRINT USING results.  The solution I used is both rather simplistic and genius -- I just make a temporary text screen page, use PRINT USING to print to it, and then read the characters back from that page before freeing it, and I store the results in a string to return back from the function.  Guaranteed to behave EXACTLY like PRINT USING does with formatting because it simply *IS* PRINT USING in action -- though with the results returned to you via a string and not printed direct to the screen.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Print Using
« Reply #2 on: June 30, 2021, 07:08:42 pm »
And RhoSigma did an nice all purpose Format$ here:
https://www.qb64.org/forum/index.php?topic=2946.0

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Print Using
« Reply #3 on: June 30, 2021, 07:31:59 pm »
SMcNeill:

A laughing cow... That could be used as a brand name for spreadable cheese... lol  Nah. Closest I could get to phonetically copying the laugh of Austin Powers... Come to think of it, English per se, is not a phonetic language... But you must catch my meaning... after all... you are a genius... wink, wink.... thank you for replying so quickly... We, on the other side of the planet, do not expect such rapid responses.... Appreciated.
ps: A soon as I post I will look for your formatter....

bplus: Thank you for the reference. Appreciated.

J
Logic is the beginning of wisdom.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Print Using
« Reply #4 on: June 30, 2021, 07:35:53 pm »
I've used some Win32 functions and even just printf as a function in a declare block that do really the same thing as PRINT USING.
Shuwatch!

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Print Using
« Reply #5 on: June 30, 2021, 10:50:55 pm »
I never got around to figuring this out, but sometimes in a program I want to assign a string variable to a formatted value. For example, if I have a number that has 4 or more decimal places, but I only want three for my processing, I can use RhoSigma's routine (or the one in your post) to do that.

As an example:

Code: [Select]
A$ = IndexFormat$("{#.###}", "1.112233", "|")
PRINT "A$ = "; A$



And RhoSigma did an nice all purpose Format$ here:
https://www.qb64.org/forum/index.php?topic=2946.0
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Print Using
« Reply #6 on: June 30, 2021, 10:57:33 pm »
Shuwatch!

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Print Using
« Reply #7 on: June 30, 2021, 11:10:49 pm »
I will have to try it (I found it in the QB64 Development internal c directory)

 Is this new? (I did not find it in the v1.5 stable release of QB64)?

@George McGinn He's basically doing this: https://docs.microsoft.com/en-us/windows/win32/api/strsafe/nf-strsafe-stringcbprintfa
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Print Using
« Reply #8 on: July 01, 2021, 02:20:24 am »
I was going to mention my IndexFormat$() function too, when johnno56 came up with this, but did not, because it didn't answer his request.

Does anyone know how to simulate the Print Using command? I would like to know how the command formats the output based on the 'pattern' given by the command.

And BTW, nobody did answer it here, we are all much to fast here giving alternatives or promoting our own made functions. Or as @NOVARSEG mentioned in another post: "99% of all tech questions remain unsolved."

That's why I stepped back since the beginning of the year, making much fewer posts here than the years before.

EDIT:
Oh, and just to make it sure, this is not about offending anybody here for giving unprecise answers, it's more a resignation on my side.
« Last Edit: July 01, 2021, 03:30:53 am by RhoSigma »
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Print Using
« Reply #9 on: July 01, 2021, 09:54:34 am »
SMcNeill:

A laughing cow... That could be used as a brand name for spreadable cheese... lol  Nah. Closest I could get to phonetically copying the laugh of Austin Powers... Come to think of it, English per se, is not a phonetic language... But you must catch my meaning... after all... you are a genius... wink, wink.... thank you for replying so quickly... We, on the other side of the planet, do not expect such rapid responses.... Appreciated.
ps: A soon as I post I will look for your formatter....

bplus: Thank you for the reference. Appreciated.

J

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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Print Using
« Reply #10 on: July 01, 2021, 04:38:59 pm »
Cool. Nicely done.

Many thanks.

J
Logic is the beginning of wisdom.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Print Using
« Reply #11 on: July 01, 2021, 07:48:09 pm »
@SMcNeill - Which PRINT statement is the one that works? The PRINT in the function or the PRINT calling it?? (rhetorical)

It may be simple, but it just doesn't work, not the same as the @RhoSigma routine.

Not only does the PRINT statement I use it in not work, I cannot assign a variable (see image below) to the result of the format function.

If I were doing a simple PRINT USING "{MASK}" with no string values (such as PRINT USING "The interest charged is #.### percent") -- see second attached image.

It is a good start, but needs more work.

  [ You are not allowed to view this attachment ]  

  [ You are not allowed to view this attachment ]  


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
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Print Using
« Reply #12 on: July 01, 2021, 09:19:13 pm »
You're seeing the formatting on the next line by there not being a _TRIM$ in there.

Code: QB64: [Select]
  1. Print "FOO: "; 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$ = _Trim$(t$)
  15.     _Dest d: _Source s
  16.     _FreeImage n
  17.  

The above should fix that.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Print Using
« Reply #13 on: July 01, 2021, 09:35:08 pm »
@SMcNeill - AWESOME!

Thanks. That does the trick. I would have taken a crack at a fix, but I'm buried deep in learning QT5 on Linux in C++!

George.

You're seeing the formatting on the next line by there not being a _TRIM$ in there.

Code: QB64: [Select]
  1. Print "FOO: "; 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$ = _Trim$(t$)
  15.     _Dest d: _Source s
  16.     _FreeImage n
  17.  

The above should fix that.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Print Using
« Reply #14 on: July 04, 2021, 06:29:01 pm »
Quote
I've used some Win32 functions

well sprigssy tell us more?
do you maybe think about this one :

HRESULT StringCchPrintfW(LPWSTR pszDest, size_t cchDest, LPCWSTR pszFormat, ...);
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////