![]() |
Fixed Length Text fields
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. |
Fixed Length Text fields
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 |
Fixed Length Text fields
That's perfect!
Mervyn "Executor" wrote in message oups.com... 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 |
All times are GMT +1. The time now is 03:47 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com