RE: Automatic Preceeding Zeros in a field e.g. 00001234

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jay Vinton (JayVinton_at_discussions.microsoft.com)
Date: 06/19/04


Date: Fri, 18 Jun 2004 21:55:01 -0700


> are not yet 8 characters be preceeded by zeros without the
> user having to input the zeros.

If the data needs to be a number, you must deal with the formatting in code at runtime. If your objective is to always have 8 characters in the table, then it should be type String.

Assuming the second case, make the serial number type Text and massage it in code before saving.

This is a good time to stop and think. Will today's serial number format be workable in the future? What if you want to change "00000123" to "ABC-0123" or "ABC-XY-1234567890-P"? If you plan ahead, you'll save a lot of grief when things change.

To solve your immediate problem:

Dim str as String

str = CStr(123)

Do While (Len(str) < 8)

   str = "0" & str

Loop

' str = "00000123"

Jay



Relevant Pages

  • Re: Delete Hit Counter/Reset
    ... there were 11 characters shown all ... zeros except for the end digit which I changed to zero. ... >FrontPage Resources, WebCircle, MS KB Quick Links, etc. ... >> just publishing straight from Front Page. ...
    (microsoft.public.frontpage.client)
  • Re: range as test
    ... padded with leading zeros to provide a string length to whatever you want. ... simply copy the other cells with alpha and alpha/numeric data. ... a mixture of characters. ... They should all be numbers then and sort correctly. ...
    (microsoft.public.excel.programming)
  • Re: Compiler issue or something in F95 standard?
    ... J.F. Cornwall wrote: ... > Does indeed look like zeros... ... Looks like a fine sample for a bug-report to me. ... len_trim said the length was 40, you don't obviously see 40 characters ...
    (comp.lang.fortran)
  • Re: Question about random numbers
    ... > Can a string of zeros, say 64 characters long be considered a random ... is the same as the chances of *any* other 64 character sequence... ... 64 identical characters is a little suspicious, ... "they threw a rope around yer neck to watch you dance the jig of death ...
    (sci.crypt)
  • Simple question for yous......
    ... Hey gurus, ... If, say, I have a URL (or any "path" type string come to think of it), how ... to use it as a path, I just want to truncate it from display purposes. ... ".../" for those bits of the path that make it go over 50 characters. ...
    (comp.lang.perl.misc)