Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function basCentTextMsg(strIn As String, LineLen As Single) As Boolean
Dim strLen As Integer
Dim Idx As Integer
Dim MySpace As Single
Dim MyWords As Variant
Dim WdLen() As Single
Dim MyLine As String
Dim MyText As String
Dim blnStrtLn As Boolean
Printer.ScaleMode = vbInches
MyWords = Split(strIn, " ") 'Create an Array of WORDs from input
ReDim WdLen(UBound(MyWords)) 'Array of Word Lengths
'Get the length of Each WORD, WITH the Trailing Space
Idx = 0
Do While Idx <= UBound(MyWords)
MyWords(Idx) = MyWords(Idx) & " "
WdLen(Idx) = Printer.TextWidth(MyWords(Idx))
Idx = Idx + 1
Loop
Idx = 0
Do While Idx <= UBound(MyWords)
If (Printer.TextWidth(Trim(MyLine & MyWords(Idx))) <= LineLen) Then
MyLine = MyLine & MyWords(Idx)
blnStrtLn = True
Else
MySpace = LineLen - Printer.TextWidth(Trim(MyLine))
NSpaces = (MySpace / Printer.TextWidth(" ")) / 2
MyText = MyText & Space(NSpaces) & Trim(MyLine) & Space(NSpaces) & vbCrLf
blnStrtLn = False
MyLine = MyWords(Idx)
End If
Idx = Idx + 1
Loop
If (blnStrtLn = True) Then
MySpace = LineLen - Printer.TextWidth(Trim(MyLine))
NSpaces = (MySpace / Printer.TextWidth(" ")) / 2
MyText = MyText & Space(NSpaces) & Trim(MyLine) & Space(NSpaces) & vbCrLf
blnStrtLn = False
MyLine = ""
End If
MsgBox MyText, vbOKOnly, "Centered Text MsgBox"
End Function
Public Function basTstCentMsg()
Dim MyStr As String
Dim MyWidth As Single
Dim MyRtn As Boolean
MyStr = "Tomorrow and tomorrow and tomorrow "
MyStr = MyStr & "creeps this petty pace from day to day, "
MyStr = MyStr & "to the last syllable of recorded time."
MyWidth = 2.5
MyRtn = basCentTextMsg(MyStr, MyWidth)
End Function