Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assign print using to a string.
#3
(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:

Code: (Select All)
'sample assigning formatted string from print using to a variable:
Rem x$ = Print Using "###"; 100
X = FreeFile
F$ = "tempfile.bak"
Print "Enter value";
Input Z#: If Z# = 0# Then Z# = 100#
Print "Enter format";
Input Z$: If Z$ = "" Then Z$ = "###"
'write print using value
Open F$ For Output As #X
Print #X, Using Z$; Z#
'read print using value
Close
Open F$ For Input As #X
If EOF(X) = 0 Then
  Line Input #X, S$
  Print S$ ' this is the output value
End If
Close
End
Although I cannot find a more efficient way to do this..

Erik.
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.

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.  Smile

Same basic concept as this as well, except it uses SCREEN instead of file access to achieve the same results.
Reply


Messages In This Thread
Assign print using to a string. - by eoredson - 03-30-2024, 03:29 AM
RE: Assign print using to a string. - by SMcNeill - 03-30-2024, 04:55 AM
RE: Assign print using to a string. - by eoredson - 03-31-2024, 11:23 PM
RE: Assign print using to a string. - by eoredson - 04-01-2024, 02:54 AM
RE: Assign print using to a string. - by SMcNeill - 04-01-2024, 06:04 AM
RE: Assign print using to a string. - by eoredson - 04-02-2024, 12:52 AM
RE: Assign print using to a string. - by SMcNeill - 04-02-2024, 01:36 AM
RE: Assign print using to a string. - by eoredson - 04-02-2024, 01:49 AM
RE: Assign print using to a string. - by SMcNeill - 04-02-2024, 02:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mac print #file crlf? BlameTroi 5 339 02-16-2026, 08:42 PM
Last Post: BlameTroi
  Print strings with accents and special chars Ikerkaz 8 709 12-20-2025, 09:28 PM
Last Post: TempodiBasic
Question Experimenting with a "StringList" type for simpler handling of string arrays/lists Heimdall 18 1,227 12-19-2025, 12:51 PM
Last Post: Heimdall
  Sub not Reconizing Dim as String pmackay 18 1,476 10-16-2025, 03:32 PM
Last Post: pmackay
  Illegal string-number conversion Herve 7 774 07-07-2025, 09:53 AM
Last Post: a740g

Forum Jump:


Users browsing this thread: 1 Guest(s)