1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB overflwo error

Discussion in 'Software Development' started by Dannie2221, Oct 19, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. Dannie2221

    Dannie2221 Thread Starter

    Joined:
    Apr 6, 2003
    Messages:
    60
    Hi, I have (hopefully) a simple question regarding VB....I'm relatively new to VB so take it easy....

    I am receiveing an overflow error when trying to divide two numbers...
    Here's my code



    dim intone as integer
    dim inttwo as integer
    dim intavg as integer

    intone = val(lblX.caption)
    inttwo = val(lblY.caption)

    intavg = intone / inttwo <<<----- OverFlow Error occurs here

    lblZ.caption = intavg



    As I said, I'm new with VB and this sounds like a very simple thing that I'm overlooking, but it's getting annoying.

    Any help would be appreciated greatly.
    Thanks.
     
  2. coderitr

    coderitr

    Joined:
    Oct 12, 2003
    Messages:
    3,015
    This may not be the whole problem but you are trying to put a floating point value into an integer variable which, by definition is a whole number. (Maybe the decimal portion gets truncated in this case?)

    Try declaring your numbers as Double instead of Integer.
     
  3. TimCottee

    TimCottee

    Joined:
    Oct 10, 2001
    Messages:
    186
    Using a double may well work, but it is not necessarily the decimal portion that will give you a problem (except in the result perhaps). The reason most likely is that you have values which result in either a divide by zero error or which give you a value greater than 32768 (the maximum an integer can hold).

    Without knowing the numbers you are actually using it is difficult to say exactly why you get the error, however you need to check whether Integer is the right data type and also add some error checking perhaps to ensure that the divisor is non-zero.
     
  4. Dannie2221

    Dannie2221 Thread Starter

    Joined:
    Apr 6, 2003
    Messages:
    60
    Thanks for your replies...

    I will switch my intwinavg to dblwinavg

    However, I think the real problem is that I am dividing by zero with the number.....I will fix this and post back

    Thanks again
     
  5. Dannie2221

    Dannie2221 Thread Starter

    Joined:
    Apr 6, 2003
    Messages:
    60
    Probelm Solved!!!

    It ended up being a divide by zero error, and it was a pain in the butt to fix so I wont make that mistake again.

    I have another quick question, although it's not a big deal and you can consider this thread solved, but....

    I changed my

    intwinavg as integer to curwinavg as currency

    but now my lblZ.caption (which prints curwinavg to the screen) has too many decimals.

    Is there any way to limit and/or tell the computer to print a set amount of decimals at the end of a number, even if the last
    digit(s) is 0?

    Thanks again for your replies
     
  6. coderitr

    coderitr

    Joined:
    Oct 12, 2003
    Messages:
    3,015
    The Format() function should do it. Just specify the number of decimal places that you want in the Format parameter. For example if you want 2 decimal places displayed then ...

    Label1.Caption = Format(dblVar, "0.00")

    I think that should work but if not play around with the format parameter to get it the way you like it.

    By the way -- I just about fell out of my chair the first time I saw your signature tag. Very funny. :)
     
  7. Dannie2221

    Dannie2221 Thread Starter

    Joined:
    Apr 6, 2003
    Messages:
    60
    Thanks, the format function should do it...


    I have to admit that I cannot take full responsibilty for the quote in my sig., and that i thought it was rather amusing myself....

    After all , what better language than binary ???

    Thanks again
    TSG is the best.

    Dan
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/173192

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice