Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What is this #??? (VBA Access 2002)

    This little pound sign has appeared in some sample code in my "Code for Village Idiots" book, without any reference or explanation:

    If chkTshirt.Value = True Then
    dRunningTotal = dRunningTotal + 9.99
    End If

    IfchkBaseballCap.Value = True Then
    DRunningTotal = dRunningTotal + 12#

    The prices of the Tshirt and Baseball cap are $9.99 and $12.00 respectively. Is the pound sign after the 12 to indicate that it's 12 dollars and no cents??

    <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15> <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: What is this #??? (VBA Access 2002)

    The # after a number means that this number must be interpreted as a double precision floating point number (even though it contains no decimals). If you look up 'Double, data type' in the help index, you'll get more info.

  3. #3
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What is this #??? (VBA Access 2002)

    Why does it not appear after the other prices?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: What is this #??? (VBA Access 2002)

    9.99 contains decimals, so the VBA interpreter knows that it must be a floating point number.
    12 doesn't contain decimals, so it could as well have been an integer number. The # indicates that it must be interpreted as a floating point number even if there are no decimals.

    Here is another example: the Integer data type accomodates whole numbers up to 32,767, while the Long data type accomodates whole numbers up to 2,147,483,647. Create the following code in a module:

    Sub DataTypeTest()
    Dim lngNumber As Long
    lngNumber = 32767 + 32767
    MsgBox lngNumber
    End Sub

    If you run it, you'll get an overflow error. The interpreter sees 32767 as an Integer because that is the "smallest" data type that can accomodate this number. But 32767+32767 is outside the allowed range for Integers.

    If you replace lngNumber = 32767 + 32767 by lngNumber = 32767& + 32767&, you will get the correct answer 65534. The "&" sign forces the interpreter to see the numbers as Longs instead of Integers.

  5. #5
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What is this #??? (VBA Access 2002)

    Thanks for the explanation, Hans. It makes sense to me now.

    Have a great weekend- <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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