+ Reply to Thread
Results 1 to 19 of 19

Excel VBA ".value" / Strange Behaviour!!!

  1. #1
    ifiaz
    Guest

    Excel VBA ".value" / Strange Behaviour!!!

    Using Excel 2002 and VB6.3

    I type just four numbers 1, 8, 5 and 2. That is 1852 in A1.
    NO FORMATS AT ALL. JUST FOUR NUMBERS.

    A
    -------------
    1 | 1852 |
    -------------

    I use VBA Immediate Window to do the following

    ? Range("A1").Value
    1852.00034359738 <<<< Load of crap.

    and it returns some unnecessary numbers after the decimal point.

    ---

    Using Excel 2000 and VB6.0

    I do the same thing...

    ? Range("A1").Value
    1852 <<< Works as expected

    ----

    I am very much annoyed with this behaviour as I have to export lots of
    these values to an access database and each of those values are garbled
    after the decimal point.

    Can someone please explain the reason for this strange behaviour?

    This problem is strangely new to me as I haven't experienced this
    before.

    Is it 1) a bug in the version of excel or vba (or) 2) a configuration
    thingy?


  2. #2
    Robin Hammond
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    With Excel 2002 (XP) SP3 and VBA 6.3 I can't replicate it.

    If this happened normally we would know about it, so it sounds like there is
    something quite wrong.

    Can't imagine that this has anything to do with configuration. It's not a
    bug that would have survived for so long without a fix.

    I'm not sure where that leaves you. Anyone else have an idea before a
    reinstall?

    Robin Hammond
    www.enhanceddatasystems.com

    "ifiaz" <[email protected]> wrote in message
    news:[email protected]...
    > Using Excel 2002 and VB6.3
    >
    > I type just four numbers 1, 8, 5 and 2. That is 1852 in A1.
    > NO FORMATS AT ALL. JUST FOUR NUMBERS.
    >
    > A
    > -------------
    > 1 | 1852 |
    > -------------
    >
    > I use VBA Immediate Window to do the following
    >
    > ? Range("A1").Value
    > 1852.00034359738 <<<< Load of crap.
    >
    > and it returns some unnecessary numbers after the decimal point.
    >
    > ---
    >
    > Using Excel 2000 and VB6.0
    >
    > I do the same thing...
    >
    > ? Range("A1").Value
    > 1852 <<< Works as expected
    >
    > ----
    >
    > I am very much annoyed with this behaviour as I have to export lots of
    > these values to an access database and each of those values are garbled
    > after the decimal point.
    >
    > Can someone please explain the reason for this strange behaviour?
    >
    > This problem is strangely new to me as I haven't experienced this
    > before.
    >
    > Is it 1) a bug in the version of excel or vba (or) 2) a configuration
    > thingy?
    >




  3. #3
    Bill Martin
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    ifiaz wrote:
    > Using Excel 2002 and VB6.3
    >
    > I type just four numbers 1, 8, 5 and 2. That is 1852 in A1.
    > NO FORMATS AT ALL. JUST FOUR NUMBERS.
    >
    > A
    > -------------
    > 1 | 1852 |
    > -------------
    >
    > I use VBA Immediate Window to do the following
    >
    > ? Range("A1").Value
    > 1852.00034359738 <<<< Load of crap.
    >
    > and it returns some unnecessary numbers after the decimal point.
    >
    > ---
    >
    > Using Excel 2000 and VB6.0
    >
    > I do the same thing...
    >
    > ? Range("A1").Value
    > 1852 <<< Works as expected
    >
    > ----
    >
    > I am very much annoyed with this behaviour as I have to export lots of
    > these values to an access database and each of those values are garbled
    > after the decimal point.
    >
    > Can someone please explain the reason for this strange behaviour?
    >
    > This problem is strangely new to me as I haven't experienced this
    > before.
    >
    > Is it 1) a bug in the version of excel or vba (or) 2) a configuration
    > thingy?
    >

    --------------------------------------

    Ignoring VBA for the moment, if you look at the cell on the spreadsheet what do
    you see? If you format it to show you lots of decimal places?

    Bill

  4. #4
    ifiaz
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Trust me. It is a new blank workbook and worksheet. I just type 4
    numbers 1, 8, 5 and 2 without any formatting.

    For your info, There are no decimal places even I deliberately format
    it. I know what I am doing in excel, so be assured that the cell
    contains just four numbers.


    Following procedure prints 1852.00034359738 in the immediate window

    ---
    Sub BugTest()

    Range("A1").Value = 1852

    Debug.Print Range("A1").Value

    End Sub
    ---


    So Is reinstall the only option?


  5. #5
    NickHK
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    ifiaz,
    Can't reproduce it in Excel 2000.

    Have you tried the Detect and Repair ?

    NickHK

    "ifiaz" <[email protected]> wrote in message
    news:[email protected]...
    > Trust me. It is a new blank workbook and worksheet. I just type 4
    > numbers 1, 8, 5 and 2 without any formatting.
    >
    > For your info, There are no decimal places even I deliberately format
    > it. I know what I am doing in excel, so be assured that the cell
    > contains just four numbers.
    >
    >
    > Following procedure prints 1852.00034359738 in the immediate window
    >
    > ---
    > Sub BugTest()
    >
    > Range("A1").Value = 1852
    >
    > Debug.Print Range("A1").Value
    >
    > End Sub
    > ---
    >
    >
    > So Is reinstall the only option?
    >




  6. #6

    Re: Excel VBA ".value" / Strange Behaviour!!!


    NickHK wrote:
    > ifiaz,
    > Can't reproduce it in Excel 2000.
    >
    > Have you tried the Detect and Repair ?
    >
    > NickHK
    >


    I did Detech and Repair, same result.

    I did a Reinstall, same result.

    What should I do. Should I just uninstall office xp completely from the
    system and start over again. Please advise.


  7. #7

    Re: Excel VBA ".value" / Strange Behaviour!!!

    I did a complete UnInstall and a fresh install. Still it doesn't work.

    I hope some experts out there suggest me how I may go about fixing this
    problem.


  8. #8

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Is this problem unsolvable?

    Is there no one who can help me out?


    [email protected] wrote:
    > I did a complete UnInstall and a fresh install. Still it doesn't work.
    >
    > I hope some experts out there suggest me how I may go about fixing this
    > problem.



  9. #9
    okaizawa
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Hi,

    I suppose that probably no one had experienced that problem.
    the number 1852.00034359738 seems like the result of conversion from a
    single precision floating-point number to a double precision.
    for instance,

    Sub Test()
    MsgBox CDbl(CSng("1.852")) * 1000
    End Sub

    but AFAIK, the Value property never does so.


    What does this macro output?

    'assuming 1852 was typed in A1
    Sub Test2()
    On Error Resume Next
    Application.EnableEvents = False
    Debug.Print Range("A1").Value
    Debug.Print Range("A1").Formula
    Debug.Print Range("A1").NumberFormat

    Range("A2").Clear
    Range("A2").Value = 1852
    Debug.Print Range("A2").Value
    Debug.Print Range("A2").Formula
    Debug.Print Range("A2").NumberFormat
    Application.EnableEvents = True
    End Sub

    how about testing in the safe mode (start excel.exe with /s switch)
    see:
    How to troubleshoot startup problems in Excel
    http://support.microsoft.com/default...b;en-us;280504

    --
    HTH,

    okaizawa

  10. #10

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Hi,

    ---
    Test 1 returns

    1851.99986485288
    ---
    Test 2 returns

    1852.00034359738
    1852
    General
    1852.00034359738
    1852
    General
    ---
    One additional problem I noticed today is when I want to type in the
    code window for example:

    TestVar = 350.23

    What actually happens is...

    Once I finish entering the last '3' and click [enter], the code window
    shows as below:

    TestVar = 350.228178550713

    THIS IS VERY STRANGE!!!

    ----

    I started Excel in Safe Mode by using the [Start] -> [Run] -> EXCEL.EXE
    /S -> [Enter].

    Excel opens in [Safe Mode]

    The results are same as above. No improvements at all.

    ---

    Please give me some more suggestions so I may try. Thanks.


  11. #11
    okaizawa
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Hi fiazidris,

    Thank you for your reporting.
    at a guess, it might be a problem of OS or hardware settings.
    but I can't think of the cause.
    Do other programs calculate correctly?

    What does this do?

    Sub Test()
    Debug.Print 1 / 3
    End Sub


    the following DLL(in fp.zip) can call the _controlfp function. if you
    want to confirm the current FPU precision, try this.

    my briefcase
    http://briefcase.yahoo.com/bc/okaizawa2/lst?.dir=/a

    _control87, _controlfp
    http://msdn.microsoft.com/library/en..._controlfp.asp

    --
    HTH,

    okaizawa


    [email protected] wrote:
    > Hi,
    >
    > ---
    > Test 1 returns
    >
    > 1851.99986485288
    > ---
    > Test 2 returns
    >
    > 1852.00034359738
    > 1852
    > General
    > 1852.00034359738
    > 1852
    > General
    > ---
    > One additional problem I noticed today is when I want to type in the
    > code window for example:
    >
    > TestVar = 350.23
    >
    > What actually happens is...
    >
    > Once I finish entering the last '3' and click [enter], the code window
    > shows as below:
    >
    > TestVar = 350.228178550713
    >
    > THIS IS VERY STRANGE!!!
    >
    > ----
    >
    > I started Excel in Safe Mode by using the [Start] -> [Run] -> EXCEL.EXE
    > /S -> [Enter].
    >
    > Excel opens in [Safe Mode]
    >
    > The results are same as above. No improvements at all.
    >
    > ---
    >
    > Please give me some more suggestions so I may try. Thanks.
    >


  12. #12

    Re: Excel VBA ".value" / Strange Behaviour!!!

    This

    Sub Test()
    Debug.Print 1 / 3
    End Sub

    returns

    0.333331383035028

    ---

    I tried VBA in MSWord and the behaviour is the same as in Excel.

    ---

    I have cygwin(unix)->Perl in my pc and it returned.

    $ perl -e 'print 1/3;'
    0.333333333333333$

    ---
    I have no idea what you want me to do about _controlfp function. Also,
    your briefcase folder seems to be empty.


    Thanks.


  13. #13
    Jezebel
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Do you have a PC with the Intel floating point bug in the chip?

    My Excel VBA gives 0.333333333333333 as expected.






    <[email protected]> wrote in message
    news:[email protected]...
    > This
    >
    > Sub Test()
    > Debug.Print 1 / 3
    > End Sub
    >
    > returns
    >
    > 0.333331383035028
    >
    > ---
    >
    > I tried VBA in MSWord and the behaviour is the same as in Excel.
    >
    > ---
    >
    > I have cygwin(unix)->Perl in my pc and it returned.
    >
    > $ perl -e 'print 1/3;'
    > 0.333333333333333$
    >
    > ---
    > I have no idea what you want me to do about _controlfp function. Also,
    > your briefcase folder seems to be empty.
    >
    >
    > Thanks.
    >




  14. #14
    okaizawa
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Hi,

    in vba on my pc, setting 24-bit(single) precision to FPU,
    1 / 3 returns 0.333333343267441. so I'm not sure if it's the problem of
    FPU precision.
    anyway, if it is just problem of vba, some files or settings in your pc
    must be broken. but I don't know about relevant files and parameters.

    > Also, your briefcase folder seems to be empty.

    sorry, my fault. if you mail me, I can send the file.

    --
    HTH,

    okaizawa

    [email protected] wrote:
    > This
    >
    > Sub Test()
    > Debug.Print 1 / 3
    > End Sub
    >
    > returns
    >
    > 0.333331383035028
    >
    > ---
    >
    > I tried VBA in MSWord and the behaviour is the same as in Excel.
    >
    > ---
    >
    > I have cygwin(unix)->Perl in my pc and it returned.
    >
    > $ perl -e 'print 1/3;'
    > 0.333333333333333$
    >
    > ---
    > I have no idea what you want me to do about _controlfp function. Also,
    > your briefcase folder seems to be empty.
    >
    >
    > Thanks.
    >


  15. #15

    Re: Excel VBA ".value" / Strange Behaviour!!!

    This problem really drives me nuts... and I need a solution to this
    badly.

    If there is anything you want me to do apart from formatting c:\, i
    will go ahead and do it.

    You could get my e-mail address from the postings.

    Thanks.


  16. #16

    Re: Excel VBA ".value" / Strange Behaviour!!!

    This problem previously, about 3 months earlier NEVER existed. Between
    then and now, I haven't made any major software installation or changes
    in my system.


  17. #17
    Jezebel
    Guest

    Re: Excel VBA ".value" / Strange Behaviour!!!

    No, formatting c: is definitely the answer.



    <[email protected]> wrote in message
    news:[email protected]...
    > This problem previously, about 3 months earlier NEVER existed. Between
    > then and now, I haven't made any major software installation or changes
    > in my system.
    >




  18. #18

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Just so that everyone knows. This problem still remains to be solved.

    I haven't taken the step of formatting c:\ yet, as I believe some of
    you out there has a smart solution.


  19. #19

    Re: Excel VBA ".value" / Strange Behaviour!!!

    Follow up from microsoft.public.excel.programming [[ Excel VBA
    ".value" / Strange Behaviour!!! ]]]

    [email protected] wrote:
    > Just so that everyone knows. This problem still remains to be solved.
    >
    > I haven't taken the step of formatting c:\ yet, as I believe some of
    > you out there has a smart solution.



    Can't someone from Microsoft or an MCSE have an answer for this...?

    Please help!


+ 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