Padded Binary String
#5
(08-25-2022, 01:56 AM)mnrvovrfc Wrote: I had to write this function because it's near impossible to come up with a near-equivalent to "printf()" from C, because it could take at least two parameters. It became necessary to pad with zeroes at the front of an integer, such as giving serial numbers as filenames and making sure every single filename was the same number of characters.

Should have been able to do that "PRINT USING" trick saving to a temporary file only to enter its contents into a string, to pad an integer with zeroes, but not just with asterisks or spaces. :/

Sounds like what you wanted to do was something similar to this?  

Code: (Select All)
Dim ss(8) As String
ss(1) = "One"
ss(2) = "Two"
ss(3) = "Three"
ss(4) = "Four"
ss(5) = "Five"
ss(6) = "Six"
ss(7) = "Seven"
ss(8) = "Eight"

Color 4, 1 'so we can see our spaces

For i = 1 To 8
    Print PadBefore(ss(i), 8, "*"), PadAfter(ss(i), 8, "0")
Next


Function PadBefore$ (num$, digits, padding$)
    p$ = num$
    temp$ = String$(digits, padding$)
    Mid$(temp$, digits - Len(p$) + 1) = p$
    PadBefore$ = temp$
End Function

Function PadAfter$ (num$, digits, padding$)
    p$ = num$
    temp$ = String$(digits, padding$)
    Mid$(temp$, 1) = p$
    PadAfter$ = temp$
End Function
Reply


Messages In This Thread
Padded Binary String - by James D Jarvis - 08-25-2022, 12:35 AM
RE: Padded Binary String - by mnrvovrfc - 08-25-2022, 01:45 AM
RE: Padded Binary String - by James D Jarvis - 08-25-2022, 01:50 AM
RE: Padded Binary String - by mnrvovrfc - 08-25-2022, 01:56 AM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 04:27 AM
RE: Padded Binary String - by Pete - 08-25-2022, 04:53 AM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 04:59 AM
RE: Padded Binary String - by Pete - 08-25-2022, 06:12 AM
RE: Padded Binary String - by RhoSigma - 08-25-2022, 08:19 AM
RE: Padded Binary String - by mnrvovrfc - 08-25-2022, 03:12 PM
RE: Padded Binary String - by bplus - 08-25-2022, 04:17 PM
RE: Padded Binary String - by bplus - 08-25-2022, 04:21 PM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 06:18 PM
RE: Padded Binary String - by RhoSigma - 08-25-2022, 04:36 PM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 04:30 PM
RE: Padded Binary String - by bplus - 08-25-2022, 07:51 PM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 08:03 PM



Users browsing this thread: 11 Guest(s)