[AccessD] Re: Number vs text data type

Robert L. Stewart rl_stewart at highstream.net
Tue Oct 14 10:23:24 CDT 2003


John,

The "longest" string is the full size of the column.

Here is a function that will do it on the fly.  You would
pass the full column width, i.e. 15 as the intWidth.

Function PadLeft(strText As String, intWidth As Integer, _
  Optional strPad As String = " ") As String

     ' Pad strText on the left, so the whole output is
     ' at least intWidth characters.
     ' If strText is longer than intWidth, just return strText.
     ' If strPad is wider than one character, this code only takes
     '  the first character got padding.
     ' Parameters:
     '   strText:
     '       Input text
     '   intWidth:
     '       Minimum width of the output. If
     '       Len(strText) < intWidth, then the
     '       output will be exactly intWidth characters
     '       wide. The code will not truncate strText,
     '       no matter what.
     '   strPad (Optional, default is " "):
     '       string whose first character will
     '       be used to pad the output.
     ' Returns:
     '   Return Value:
     '       strText, possibly padded on the left with
     '       the first character of strPad.
     ' Example:
     '   PadLeft("Name", 10, ".") returns
     '       "......Name"
     '   PadLeft("Name", 10) returns
     '       "      Name"

     If Len(strText) > intWidth Then
         PadLeft = strText
     Else
         PadLeft = Right$(String(intWidth, strPad) & _
          strText, intWidth)
     End If
  End Function

Since I useBase36 for my numbering, I start my numbering
at 0000000000.  Because everything is padded with 0, the
sorting is not an issue.  I live with the performance hit
of a few milliseconds because I prefer this method.

One day, I suspect our SSNs will include letters and go to
a Base36 numbering like the license plates on our cars.
And it would be smart, which is why it will never happen
;-), if zip codes were done the same way.

I believe we agree, just saying it different ways.  8-)

Robert

At 02:59 PM 10/13/2003 -0500, you wrote:
>Date: Mon, 13 Oct 2003 12:19:14 -0500
>From: "John B." <john at winhaven.net>
>Subject: RE: [AccessD] Number vs text data type
>To: "Access Developers discussion and problem solving"
>         <accessd at databaseadvisors.com>
>Message-ID: <NGBBLIECOMAKBPEDMKEJKEMDFCAA.john at winhaven.net>
>Content-Type: text/plain;       charset="iso-8859-1"
>
>Yes, but then you have to find the longest string first and feed it to the
>format function and you have the issue of leading zeros or (whatever), etc.
>
>I realize there are many reasons to type a field one way or the other and
>there are always gray areas...
>therefore I'll revise my previous statement - its cleaner (and easier) to
>sort your data if you first properly type your data fields. In general use a
>number type for items that indicate a numeric value and a text type for
>items that just happen to include numbers.




More information about the AccessD mailing list