Whenever I try to run my program it keeps giving me an overflow error and I dont know why. The problem is shown when i call this sub:

``blueP.shootBall(blueS.x, blueS.y, blueP.ang, blueP.captured, ball.x, ball.y, ball.velx, ball.vely)``

this is the sub

``````Public Sub shootBall(ByVal x, ByVal y, ByVal ang, ByRef caputred, ByRef xb, ByRef yb, ByRef velx, ByRef vely) 'x and y are blueS.x and y
xb = System.Math.Round(x + ((18 - System.Math.Sqrt((x + 12 - (xb + 6)) ^ 2 + (y + 12 - (yb + 6)) ^ 2)) * System.Math.Cos(ang)), 5) 'moves ball out of capture range
yb = System.Math.Round(y + ((18 - System.Math.Sqrt((x + 12 - (xb + 6)) ^ 2 - (y + 12 - (yb + 6)) ^ 2)) * System.Math.Sin(ang)), 5)
caputred = False
velx = 2 * System.Math.Cos(ang)
vely = 2 * System.Math.Sin(ang)
'Form1.Timer1.Stop()
'MsgBox(velx & " " & vely & " " & System.Math.Sqrt((x + 12 - (xb + 6)) ^ 2 + (y + 12 - (yb + 6)) ^ 2))
'Form1.Timer1.Start()
xb += velx
yb += vely
End Sub``````

all the numeric variables should be decimals

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Chris11246

it runs when I comment out these parts

``````xb = x '+ ((18 - System.Math.Sqrt((x + 12 - (xb + 6)) ^ 2 + (y + 12 - (yb + 6)) ^ 2)) * System.Math.Cos(ang)) 'moves ball out of capture range
yb = y '+ ((18 - System.Math.Sqrt((x + 12 - (xb + 6)) ^ 2 - (y + 12 - (yb + 6)) ^ 2)) * System.Math.Sin(ang))``````

None of the parameters even have datatypes defined.... An overflow error is usually caused by trying to force a bad value that doesnt fit into a specific datatype.

Edited by TomW: n/a

i was able to fix the problem with something else thank you though