by Emporer (4 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 9th November 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Centers Text in Msgbox, Listview, Form Caption, Ect.
API Declarations
*The MaxChars is what the text will be centered by, if the length of Text is 10 and the MaxChars is 30, then 10 spaces will be on each side of Text.
Public Function Center(Text As String, MaxChars As Integer) As String
spcs = Int(Len(Text) / 2)
cntr = Int(MaxChars / 2)
ctr = Space(cntr - spcs) & Text & Space(cntr - spcs)
Do Until Len(ctr) = MaxChars + 3
ctr = " " & ctr
Loop
Center = ctr
End Function