Fixed Length Text fields

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.
 
E

Executor

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top