Runtime error 215?

First off, I don't know what the heck runtime error 215 is. I'm pretty sure it's some sort of math thing, like multiplying by this...or doing that...something.  Allow me to explain when I get this error:

I use a formula "Position:=320 * PosY + PosX" (Thanks Scrappy) to calculate the position of a pixel, and do all this stuff to figure out the color of that pixel and whatnot.  Anyhow, when the pixel is above the upper half of the screen, everything works fine, but as soon as it gets below the upper half, i get "Runtime error 215".

I'm in MCGA mode, and PosY and PosX are the coords for pixel placement, instead of using a number between 1 and 64000
 
If figured out it happens when PosY is 104 (that's the source of the error, not the PosX)  So 320 * 104 for some reason gives me this error?  I don't know...can anyone help?  
Thanks
hansellAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
owConnect With a Mentor Commented:
Scrappy is right at the bottom: 215 is an arithmetic overflow error and 320x104 exceeds the maximun value of integers.
But as the error is caused by the overflow and not by the assignement, you must use longint for "PosX" rather then for "Position".

Regards
  ow

0
 
hansellAuthor Commented:
Edited text of question
0
 
hansellAuthor Commented:
Edited text of question
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
hansellAuthor Commented:
Edited text of question
0
 
scrapdogCommented:
I think I know exactly what your problem is.  You declared Position as an Integer.

An Integer can only hold values between -32768 and 32767.

104*320 = 33280

and this will cause an overflow error, since 33280 is > 32767.


To remedy this, your best bet is to declare position as type Word.  The Word type uses the same amount of memory as the integer type, but the range of values is from 0..65535

When you declare your variable, do it like this:

Position :Word;


rather than this:

Position :Integer;


A variable of type word can safely handle what you are doing, because it seems that your highest value of position is 64000, and word can handle this.


In the future, if you have this error again in another program, remember the ranges of these types:

Integer   -32768 to 32767
Word      0 to 65535
Longint   -2147483648 to 2147483648

If, for example, you need an integer that will require values greater than 32767, you can use Word, or Longint to suit your needs.

Integers and Words are stored using 2 bytes, and Longints are stored using 4 bytes, if you're curious.

Anyway, try using type Word in your program and it will eliminate the error.  

scrappy
0
 
daittCommented:
I think the answer is absolutely exact. Why we don't close this question?
0
 
hansellAuthor Commented:
Your answer sounded great, but I'm still getting the error.  I've tried position:word and position:longint...

I get the Error 215:Runtime Error at the following line:

Position:=320 * PosY + PosX;

It's exactly like that....PosY is still 104 when i get this error...any other ideas?  

I saw something about a divide by zero bug with 200mhz cpu's but i'm not dividing so...btw my cpu is a 233mhz pentium if that helps?

Any other ideas?

0
 
hansellAuthor Commented:
I guess my above comment didn't reject the answer...

Why doesn't Word or LongInt work?  I see why it should...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.