CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    israel
    Posts
    99

    how to detect an overflow?

    hello,

    i m creating a calculator in 16 bit. how can i detect an overflow in run time?

    ohad


  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: how to detect an overflow?

    one way is to use larger data type to store the result and check for overflow. for instance,


    dim i as integer
    dim j as integer
    dim l as long

    l = i + j

    if l > 32767 then
    'overflow
    end




    second way, use On Error Goto ....

    [vbcode]
    On Error Goto ErrorTrap
    dim i as integer
    dim j as integer
    dim k as integer

    k = i + j

    exit function
    ErrorTrap:

    'if k overflow, this part of code will be executed ...



    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

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

Featured