Annette,
Try this
Option Explicit
Private Sub Command1_Click()
'fill spaces with "-"
Text1.Text = CenterString(InString:="String", StringWidth:=12, Filler:="-")
End Sub
Private Sub Command2_Click()
'fill spaces with default filler " "
Text1.Text = CenterString(InString:="String", StringWidth:=12)
End Sub
Public Function CenterString(InString As String, StringWidth As Integer,
Optional Filler As String = " ") As String
Dim intSpace As String
Dim intLeft As Integer
Dim intRight As Integer
intSpace = StringWidth - Len(InString)
If intSpace <= 0 Then
CenterString = InString 'no space available
Else
intLeft = intSpace \ 2
intRight = intLeft + intSpace Mod 2 'if odd make more space from the
right
CenterString = String(intLeft, Filler) & InString & String(intRight,
Filler)
End If
End Function
Good Luck,
Vladimir
Quote:
>Is there a Format, or other function, that will format a string, centered
>within a certain width?
>For example, if I did Format("String",12) it would return " String
> "?
>Thanks,
>Annette Gates