Fixed Length Text fields

  • Thread starter Thread starter Mervyn Thomas
  • Start date Start date
M

Mervyn Thomas

Can anyone suggest how I can right pad a text field so that it always has a
fixed length of 18. I have an import requirement that a field is 18
characters long but the source data is variable length and unfortunately I
cannot use delimiters in the import.
 
Hi Mervin,

I have created a common function:

Public Function RightPad(ByVal sOriginal As String, ByVal iLength As
Integer) As String
If Len(sOriginal) < iLength Then
RightPad = sOriginal & Space(iLength - Len(sOriginal))
Else
RightPad = Left(sOriginal, iLength)
End If
End Function

It takes 2 parameters:
1) The string
2) The length it must have.

If it is shorter some spaces will be added at the end.
If if is to long it will be truncated at the given length.

HTH.


Executor
 
Back
Top