+ Reply to Thread
Results 1 to 2 of 2

Overflow error

  1. #1
    Grd
    Guest

    Overflow error

    Hi,

    I've created a simple funcion to calculate the volume based on three inputs,
    height, width and depth. I've make the variables bytes. When the result of
    the volume is over 255 I get an overflow error. See the function below:

    Function volume(height As Byte, width As Byte, depth As Byte)
    volume = height * width * depth

    End Function
    --------------------------
    Sub test()

    Debug.Print volume(12, 22, 1)

    End Sub

    Can anyone help with why I'm getting the error. Thanks in advance

    Regards
    Janet

  2. #2
    Tim Williams
    Guest

    Re: Overflow error

    You should specifiy the datatype of the return value, and maybe also dim
    your parameters as integer.

    The error is because your multiplication is producing a value too large for
    the variable's size.


    Tim




    "Grd" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I've created a simple funcion to calculate the volume based on three
    > inputs,
    > height, width and depth. I've make the variables bytes. When the result of
    > the volume is over 255 I get an overflow error. See the function below:
    >
    > Function volume(height As Byte, width As Byte, depth As Byte)
    > volume = height * width * depth
    >
    > End Function
    > --------------------------
    > Sub test()
    >
    > Debug.Print volume(12, 22, 1)
    >
    > End Sub
    >
    > Can anyone help with why I'm getting the error. Thanks in advance
    >
    > Regards
    > Janet




+ 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