Assign print using to a string. - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Assign print using to a string. (/showthread.php?tid=2553) Pages:
1
2
|
Assign print using to a string. - eoredson - 03-30-2024 An interesting code snippet to get a string variable from print using: Code: (Select All) 'sample assigning formatted string from print using to a variable: Erik. RE: Assign print using to a string. - TerryRitchie - 03-30-2024 (03-30-2024, 03:29 AM)eoredson Wrote: An interesting code snippet to get a string variable from print using:Hmmm, that's interesting. In other words what you are looking for would be something like this: Num = 100 use$ = "This is a test -> ###" s$ = USING use$, Num s$ would then contain: This is a test -> 100 I've always used USING to format output to a printer or file but I never gave any thought to USING being utilized in this manner. It's an interesting concept though. The only way I see to do this (besides the method you showed above) would be to create functions and/or subs to preformat strings for you. RE: Assign print using to a string. - SMcNeill - 03-30-2024 (03-30-2024, 04:17 AM)TerryRitchie Wrote:(03-30-2024, 03:29 AM)eoredson Wrote: An interesting code snippet to get a string variable from print using:Hmmm, that's interesting. In other words what you are looking for would be something like this: My old Format$ Function (which I've apparently lost somewhere and had to reshare here: https://qb64phoenix.com/forum/showthread.php?tid=2554 ) does this for us. Send if a value and a format string, and then get back the result in the format you specified. Same basic concept as this as well, except it uses SCREEN instead of file access to achieve the same results. RE: Assign print using to a string. - eoredson - 03-31-2024 You mean something like this: Code: (Select All) 'another method to assign a formatted value to a string RE: Assign print using to a string. - eoredson - 04-01-2024 The only 2 problems with using the screen is: 1)Have to store/restore area of screen being written to. 2)What if print using output is greater than 80 chars. Otherwise, yes, screen is more efficient then file access.. Erik. RE: Assign print using to a string. - TerryRitchie - 04-01-2024 (04-01-2024, 02:54 AM)eoredson Wrote: The only 2 problems with using the screen is: Steve has shown how you can do this here: https://qb64phoenix.com/forum/showthread.php?tid=2554 Just create another SCREEN 0 image of any size you like. It's quite clever. RE: Assign print using to a string. - SMcNeill - 04-01-2024 (04-01-2024, 02:54 AM)eoredson Wrote: The only 2 problems with using the screen is: 1) Just make the screen STATIC so you don't need to create/free it over and over. It's only going to be a few hundred bytes of memory in the end, after all. 2) You're going to format a single number to more than 80 characters? That's SOME number!! Even then, the solution is to just be certain you make the screen large enough to hold the value to begin with. _NEWIMAGE(800,1,0) <-- Is 800 characters enough for you to format your number? _NEWIMAGE(9999, 1, 0) <--- is 9,999 characters enough? A normal screen 0 screen is 80x25 characters = 4000 -- you've now got over twice that limit! Just change the size of that _NEWIMAGE so it's large enough to format that value that you want formatted. RE: Assign print using to a string. - eoredson - 04-02-2024 Try: Print Using "&"; String$(800, "#") is greater than 80 char... Hee. https://qb64phoenix.com/qb64wiki/index.php/PRINT_USING Or something useless like: Code: (Select All) For x = 1 To 1024 RE: Assign print using to a string. - SMcNeill - 04-02-2024 Try: Code: (Select All) Print FormatStr(String$(800, "#"), "&") PS: I want to see the screen where you're printing your output to. What size monitor are you using for: For x = 1 To 1024 x$ = x$ + Str$(x) Next Print Using "&"; x$ At a max of characters per value (space + 4 digit number + space), that's about 6000 characters. Since Print UUsing doesn't do word wrap, you'd almost expect to see all 6000 of those characters on a single line. At 8 pixels width, that's only 48000 pixels -- while Windows itself only allows *any* screen to be 32000 pixels... Something seems wrong here, mate. RE: Assign print using to a string. - eoredson - 04-02-2024 Quote:Something seems wrong here, mate.I was just kidding. I have no use for such code. |