+ Reply to Thread
Results 1 to 3 of 3

Fixed Length Text fields

Hybrid View

  1. #1
    Mervyn Thomas
    Guest

    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.



  2. #2
    Executor
    Guest

    Re: 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


  3. #3
    Mervyn Thomas
    Guest

    Re: Fixed Length Text fields

    That's perfect!
    Mervyn
    "Executor" <wouter.magre@sogeti.nl> wrote in message
    news:1141733330.553804.224980@z34g2000cwc.googlegroups.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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1