Format String Centered? 
Author Message
 Format String Centered?

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



Tue, 15 Feb 2000 03:00:00 GMT  
 Format String Centered?

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



Tue, 15 Feb 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Not able to format with String.Format

2. Help Needed for Right Aligning strings and Centering

3. Centering a form doesn't center the form

4. Format part of a string italics

5. String Search in Hyperlink formatted field A97

6. Formatting a string variable in an SQL statement.

7. help how to convert time string into time format

8. How To Format a String

9. How to convert Outlook date format into ISO 8601 DateTime Z string

10. changing formatting for defined text strings

11. String Formatting

12. Formatting a String Variable

 

 
Powered by phpBB® Forum Software