? Printing non left-alligned text? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Printing non left-alligned text?

  • #1 ✎ 262 Shelly How would you print text which isn't centered, but isn't left-aligned? Posted
  • #2 ✎ 184 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies With some code of course. DEF PRINTR T$ DIM I,P$[1],T0$=T$,L=!DISPLAY()*50+DISPLAY()*40 WHILE LEN(T0$)DIV L FOR I=0 TO L-1:PUSH P$[LEN(P$)-1],SHIFT(T0$):NEXT I PUSH P$,"" WEND P$[LEN(P$)-1]=" "*MAX(L-LEN(T0$),0)+T0$ WHILE LEN(P$):PRINT SHIFT(P$):WEND END I can't test it atm. Does it work? Probably. Will someone come along and write some better code? Yes! Edit: Okay, after extensive editing I think it'll work. Oh, and by not centered and not left-aligned, I am assuming you mean right-aligned, unless you are not...? Probably a better version: DEF PRINTR T$ DIM Y%=CSRY,P$,T0$,L%=!DISPLAY()*50+DISPLAY()*40 WHILE LEN(T0$)>.PUSH P$,SHIFT(T0$) IF LEN(P$)==L%THEN LOCATE.,Y%?P$P$=""INC Y% WEND UNSHIFT P$," "*(L%-LEN(P$))?P$LOCATE.,Y%+1 END Posted Edited by MZ952
  • #3 ✎ 901 snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself Unless I'm misunderstanding, you can just use FORMAT$() to right-align text to a certain width. VAR W$="Right-align me" PRINT FORMAT$("%25S", W$) This will print W$ as though it had just enough leading spaces to be 25 characters wide, with the actual text at the end (or right side if you will.) For reference, the text console is 50 characters wide. Posted
  • #4 ✎ 184 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies If the text is longer than 25 characters, this method fails. Posted
  • #5 ✎ 901 snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself
    If the text is longer than 25 characters, this method fails.
    Of course, you can just change the width if you need to. Just an illustrative example.
    Posted
  • #6 ✎ 1573 12Me21 Head Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website This will cut off the text if it's longer:PRINT FORMAT$("%25.25S", W$) Posted