|
Post by johnno56 on Feb 1, 2024 1:31:33 GMT -6
Does anyone have a routine to convert the QBasic "Print Using" command?
J
|
|
|
Post by n00b on Feb 1, 2024 2:34:47 GMT -6
Here is a simple function to convert numbers using the format:
Function PrintUsing(formatString$, value) result$ = "" totalWidth = 0 decimalPlaces = 0 inDecimal = false decimal_index = -1
' Parse the format string to determine total width and decimal places for ch_index = 0 to Len(formatString$)-1 ch$ = Mid(formatString$, ch_index, 1) if ch = "#" then if inDecimal then decimalPlaces = decimalPlaces + 1 end if totalWidth = totalWidth + 1 elseif ch = "." then inDecimal = true decimal_index = ch_index end if next int_val = Int(value) ds$ = Insert(Replace(str(frac(value)) + StringFill("0", decimalPlaces), ".", ""), ".", decimalPlaces+1) decimal_val$ = Str(Round(Val(ds$))) output_str$ = Str(int_val) + "." + decimal_val Print output_str$ End function
PrintUsing("##.#", 66.789)
You would need to modify it to handle the other formatting QBasic can do but most formatting is just the decimal places so it does cover most situations I have seen.
|
|
|
Post by johnno56 on Feb 1, 2024 5:10:36 GMT -6
Cool... I will check it in the morning. Much appreciated. Thank you.
J
|
|