Hi Sharon
I know this is not exactly a solution to your question, but you might find it useful nonetheless.
I had a situation where i had to write EDI data files which are essentially fixed-width text files, but very strictly formatted; in my VBA code I had to format strings in all sorts of ways, so i made myself a custom formatting function, it looks like this:
Function padtrim(mystr As String, length As Integer, rightJ As Boolean, padchar As String)
mystr = Trim(mystr)
padtrim = mystr
If Len(mystr) > length Then
If rightJ = True Then
padtrim = right(mystr, length)
Else
padtrim = Left(mystr, length)
End If
End If
If Len(mystr) < length Then
If rightJ = True Then
padtrim = String(length - Len(mystr), padchar) & mystr
Else
padtrim = mystr & String(length - Len(mystr), padchar)
End If
End If
End Function
The function is used by passing it your string, the length you want back, A boolean value indicating if you want right or left justified, and the character with which you want to pad out the string if too short.
So if you do:
newstring = padtrim("123",10,True,"0") you get "0000000123"
newstring = padtrim("123",10,False,"0") you get "1230000000"
newstring = padtrim("123",5,True," ") you get " 123"
newstring = padtrim("123",5,False," ") you get "123 "
newstring = padtrim("1234567",5,True," ") you get "34567"
newstring = padtrim("1234567",5,False," ") you get "12345"
This is called 'procrustean' string handling, named after an innkeeper in Greek mythology called Procrustes who, if his guests did not fit the beds, either stretched them on a rack, or cut off their feet!
HTH
Mike