Quote Originally Posted by Edgemeal View Post
So if you wanted to use a fixed length string you'd have to make a class or function and call it on your string everytime you changed it?

Maybe something like... ?....
Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    ' fix to 8 char length
    Debug.Print(">" & FixStrLength("1234567890", 8) & "<")
    ' fix to 4 char length
    Debug.Print(">" & FixStrLength("123", 4) & "<")
End Sub

Private Function FixStrLength(strIn As String, MaxLength As Integer) As String
    If strIn.Length > MaxLength Then ' remove excess chars.
        Return strIn.Substring(0, MaxLength)
    ElseIf strIn.Length < MaxLength Then 'add needed spaces to fill to length
        Return strIn & New String(" "c, MaxLength - strIn.Length)
    Else
        Return strIn  'nothing to do
    End If
End Function
Hi Edgemeal,

Yeah I thought about writing my own class to do this, but I just figured something like this is common and built into the .net framework.

Thanks,

Strick