03-30-2024, 04:55 AM
(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:
Although I cannot find a more efficient way to do this..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
Erik.
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.
Same basic concept as this as well, except it uses SCREEN instead of file access to achieve the same results.