Results 1 to 3 of 3

Thread: Byte Addition

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Location
    Milwaukee, Wi
    Posts
    28
    Hi,

    I want to add two byte variables together and if the resulting value is greater than 255, then i want the sum to be set at 255. So far, i have had no luck at all. i tried setting up a temporary int variable like this:

    dim x,y,sum as byte
    dim temp as integer

    temp = x+y

    if temp >255 then
    sum = 255
    else
    sum = temp
    end if

    but i still get an overflow error. How do i fix this???

    Shaheeb

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    You have to do something like this:


    Code:
      temp = CInt(x) + CInt(y)
    -Shickadance

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    you might have to do

    Code:
    sum = CByte(temp)
    Also, I am not positive though

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