Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Using
#2
(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")
Reply


Messages In This Thread
Print Using - by johnno56 - 03-20-2025, 01:00 AM
RE: Print Using - by 1micha.elok - 03-20-2025, 07:37 AM
RE: Print Using - by johnno56 - 03-20-2025, 09:46 AM
RE: Print Using - by Marcus - 03-21-2025, 04:57 PM
RE: Print Using - by johnno56 - 03-21-2025, 08:31 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)