QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: johnno56 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....
-
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.
-
And RhoSigma did an nice all purpose Format$ here:
https://www.qb64.org/forum/index.php?topic=2946.0
-
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
-
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.
-
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:
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 He's basically doing this: https://docs.microsoft.com/en-us/windows/win32/api/strsafe/nf-strsafe-stringcbprintfa (https://docs.microsoft.com/en-us/windows/win32/api/strsafe/nf-strsafe-stringcbprintfa)
-
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 (https://docs.microsoft.com/en-us/windows/win32/api/strsafe/nf-strsafe-stringcbprintfa)
-
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.
-
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
PRINT format$
("###.###", "123.456789") PRINT format$
("###,.##", "123456789.987654321")
format$ = t$
-
Cool. Nicely done.
Many thanks.
J
-
@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.
[ This attachment cannot be displayed inline in 'Print Page' view ]
[ This attachment cannot be displayed inline in 'Print Page' view ]
PRINT format$
("###.###", "123.456789") PRINT format$
("###,.##", "123456789.987654321")
format$ = t$
-
You're seeing the formatting on the next line by there not being a _TRIM$ in there.
Print "FOO: "; format$
("###.###", "123.456789") Print format$
("###,.##", "123456789.987654321")
The above should fix that.
-
@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.
Print "FOO: "; format$
("###.###", "123.456789") Print format$
("###,.##", "123456789.987654321")
The above should fix that.
-
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, ...);
-
Yes, I've used StringCchPrintf. Also StringCbPrintf