Results 1 to 5 of 5

Thread: Overflow!!!

  1. #1
    snip
    Guest

    Overflow!!!

    I write the follow code:

    Code:
        Dim a As Double
        
        a = 20001 * 8
    It will have overflow error, however, as 20001 * 8 = 160008, if I assign a directly to 160008, it will be fine, i.e.

    Code:
       a = 160008
    I think the problem is come from the * operator, but how could I solve this?? I really need to handle such a big value..

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    The explanation why the following works is here:
    http://www.vbforums.com/showthread.p...274#post455274

    The following will force the intermediate result to be held in a double:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim a#
    3.  
    4. a = 20001# * 8
    5. MsgBox a
    6. End Sub

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Damn speed typist Nucleus
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Not bad for a 2-4 finger typist .

  5. #5
    snip
    Guest
    Thank Nucleus, it work now!!

Posting Permissions

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



Click Here to Expand Forum to Full Width