Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text-centring subs
#3
Edit: Woops, I just realized you guys were talking about non-graphical screens, oh well. People that use graphical screens can use mine.

I've been wanting one of these for awhile. So I just tried to make my own using _PRINTSTRING and it works great! I also happened to find an example one in the Wiki pages when I was looking up Width, but I like mine. Smile
This will center the text you type from the INPUT to the center of the screen. It also asks you if you want it centered by height or not. If not, it will ask you what height pixel you wish to use. 
This isn't a SUB, but you could easily make it into one if you wish to.

Code: (Select All)

'This will center text in the middle of the screen.

Dim a As Long
start:
height = 0
ht = 0
Cls
a& = _NewImage(800, 600, 32)
Screen a&
Input "Print text to center -> ", a$
Input "Do you also want it centered by height (Y/N) ", yn$
If Left$(yn$, 1) = "Y" Or Left$(yn$, 1) = "y" Then
    height = 1
Else
    Print "Screen height: ", _Height(a&)
    Input "Type a height pixel here for text: ", ht
End If

Cls
aa = Len(a$)
bb = aa * 8
w = _Width(a&)
l = _Height(a&)
center = w / 2
halfbb = center - (bb / 2)

If height = 1 Then
    _PrintString (halfbb, l / 2), a$
Else
    _PrintString (halfbb, ht), a$
End If

Locate 35, 1: Input "Again (Y/N) ", ag$
If Left$(ag$, 1) = "y" Or Left$(ag$, 1) = "Y" Then GoTo start:
End
Reply


Messages In This Thread
Text-centring subs - by PhilOfPerth - 6 hours ago
RE: Text-centring subs - by SMcNeill - 5 hours ago
RE: Text-centring subs - by SierraKen - 4 hours ago



Users browsing this thread: 1 Guest(s)