Author Topic: Overflow  (Read 2815 times)

0 Members and 1 Guest are viewing this topic.

Offline Prithak

  • Newbie
  • Posts: 56
  • Life itself is a Programming Language!
    • View Profile
    • My Programming Language
Overflow
« on: August 21, 2018, 03:24:09 am »
I've been working on two-dimensional arrays recently because my school is teaching it right now and I was making a very simple game about fighting or somethin' then I got this error.

"OVERFLOW"

What does it mean and can it be fixed? If you need the program then ask me. I won't post it in this box because it is a hassle to set up the whole thing! So. Yeah!

Can i fix this?
CLS
IF computer$ = "ON" THEN
me$ = "Happy!"
ELSE
me$ = "Time To Draw!"
END IF
END

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Overflow
« Reply #1 on: August 21, 2018, 10:36:07 am »
'overflow: Let say, you use _UNSIGNED _BYTE type variable. This type maximum value is 255. What, if this value is bigger?

DIM a AS _UNSIGNED _BYTE
a = 255
PRINT a
a = 256
PRINT a

'as you see, second value is not 255, but 0. Its, because QB64 test it and return this  value after overflow back to begin.

a = 255 * 2 'return 254 - because 255 * 2 = 510 = 510 - 256 = 254. Zero is as 1.
PRINT a

'so for testing it, you muss know variable type and maximum value, which can be used for this variable type.