Re: Long Integer truncates 0 at beginning of number

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



Let me see if I understand this correctly

I can leave the number as 27987 in the database, but if I need to show it,
say in a textbox, I can just format it like this:

Dim id as Long

id = 27987

sometextbox.value = Format(id, "000000")

Is that right?
If it is I'll be so excited!

--
Piper


"Klatuu" wrote:

No, I don't think you need to redo all your coding. If the field in the
table where the value is stored is Numeric/Long, then anything that
references or modifies it as a number can be left as is.

The only time you need to present it as text is when you want to show it to
a human in that format. Then, you use the Format function or property as
Jeff said. That does not chage the original value or type unless you do so
specifically. For example, let's say you want to present it in a message box:

MsgBox "This Is A Formatted Number " & Format(lngSomeNumber, "000000")

Nothing has changed about the variable lngSomeNumber. It is just formated
for presentation so that it will always be presented with enought zeros to
make it six characters long.

If you want to change it to a string:
strConvertedNumber = Format(lngSomeNumber, "000000")

Now lngSomeNumber has still not changed, but we have a string variable that
contains a text representation of the number.


--
Dave Hargis, Microsoft Access MVP


"Piper" wrote:

Thanks for the response - I'm bummed, now I have to make it a string and
convert all that coding.

Oh well - I suppose I should have figured that out before I started coding!

Thanks
--
Piper


"Jeff Boyce" wrote:

Piper

Access is doing EXACTLY what you are telling it to do. Integers, Long or
otherwise, are whole numbers. From basic math, 1, 01, 001, and
00000000000000001 are all the same value, i.e,. 1!

If you need to show the digit 0 as the first character in a string of
characters (digits), then it is likely NOT a number (something you'd
add/subtract/multiply/divide). If you aren't doing math with it, maybe it's
"text", not "number".

Or, if you want to SEE preceding zeros on a true number (math, remember),
you can use the Format property or function to display those, regardless of
the value Access stores.

Regards

Jeff Boyce
Microsoft Office/Access MVP

"Piper" <Piper@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3AB225A2-2462-43FF-A6DD-2EB40BA27A93@xxxxxxxxxxxxxxxx
Hi -

I have a field of type Long, the data that goes in the field are numbers
like 027987 and 564982

Every time I enter a number with a 0 in front access takes the 0 out and
leaves me with 27987.

Is there anything I can do to keep the field type long? I've done a lot of
programming and I hate to loose it if I had to change the field type to
String.

Thanks
--
Piper




.



Relevant Pages

  • printing bits ... the right way
    ... \param str The array of characters where the resulting string is to ... \param format A custom format string specific to converting ... render an integer type into a binary string. ...
    (comp.lang.c)
  • Re: Reading LAST line from text file without iterating through the file?
    ... ASCII character values are limited to the 0-127 range. ... these days we use the 8th bit for accented characters instead ... Lines are a record format. ... way to represent an ArrayList<String> losslessly in a single String ...
    (comp.lang.java.programmer)
  • Re: Compare Instr() and IndexOf() performance
    ... The largest file is 780 kb, the format of the file is fixed length record ... (17 characters), I am always searching this files on first 10 characters ... but the contents of this file changes every ... If you just calculate the maximum number of string comparisions that may be ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: How many bytes per Italian character?
    ... to format an ANSI string, and yes, there's a possibility that it isn't implemented on CE, ... you went from a discussion about the number of bytes in Italian characters to a ... Remote Registry Editor rather than in Windows CE. ...
    (microsoft.public.vc.mfc)
  • Re: Data Table Fields
    ... than the "field type" as you asked. ... Opinions should be accepted for what they are and not criticized. ... >> and you want to set its Format proerty to Short Date, ... >> intType As Integer, varValue As Variant, Optional strErrMsg As String) ...
    (microsoft.public.access.tablesdbdesign)