I am trying to convert a QB64 program and I have encountered the command PRINT USING.
Does anyone know of a procedure to format text to simulate the command?
eg: PRINT USING "#,###,#00 Lives: # <--JAKE"; score2; lives2
if the score is 1234 and lives are 3: output would be: 1,234 Lives: 3 <--JAKE
(03-20-2025, 01:00 AM)johnno56 Wrote: [ -> ]I am trying to convert a QB64 program and I have encountered the command PRINT USING.
Does anyone know of a procedure to format text to simulate the command?
eg: PRINT USING "#,###,#00 Lives: # <--JAKE"; score2; lives2
if the score is 1234 and lives are 3: output would be: 1,234 Lives: 3 <--JAKE
Perhaps like this one : ...
Code:
' Example values
score2 = 1234
lives2 = 3
pln "score2 = "+score2
pln "lives2 = "+lives2
' Step 1: Format score2 with commas
formattedScore = ""
tempScore = score2
commaCounter = 0
while tempScore > 0
digit = tempScore % 10
tempScore = int(tempScore / 10)
formattedScore = str(digit) + formattedScore
commaCounter = commaCounter + 1
if commaCounter % 3 = 0 and tempScore > 0 then
formattedScore = "," + formattedScore
endif
wend
if len(formattedScore) < 2 then
formattedScore = right("00" + formattedScore, 2)
endif
' Step 2: Format lives2 as a single digit
livesStr = str(lives2)
' Step 3: Print the final output
pln formattedScore+" Lives: "+livesStr+" <--JAKE"
pln
pln
system("pause")
Thank you. Much appreciated...

I can add some optional parameters to the 'str' function for that if you want?
Thanks Marcus. But the odds of anyone else wanting to print formatted text, such as Print Using, could pretty remote and the time spent making the change to 'str()' may not be worth it... lol But I do appreciate the offer... thank you.