[英]VB.NET OverflowException was unhandled
I have a problem in VB 2008 that gives me an error: " OverflowException was unhandled. " in that piece of code: The error is highlights the Next b
我在VB 2008中有一个问题,给我一个错误:在那段代码中:“ OverflowException未处理。”该错误突出显示了
Next b
Dim gfx As Graphics
Dim a,r,g,b As byte
Dim left As Integer
Dim lStep As Integer = 1
For left = 0 To Me.ClientRectangle.Height Step lStep
For a = 1 To 255
For r = 1 To 255
For g = 1 To 255
For b = 1 To 255
gfx.DrawLine(New Pen(Color.FromArgb(a, r, g, b)), 0, left, Me.ClientRectangle.Width, left)
Next b
Next g
Next r
Next a
Dim a,r,g,b As byte
That's where your problem started. 那是您的问题开始的地方。 Your For loops increment from 1 to 255, stopping when the value reaches 256. But that is not possible for a Byte, it can only store a value between 0 and 255. Kaboom when the
Next
statement tries to increment it from 255 to 256. 您的For循环从1递增到255,在值达到256时停止。但是对于字节来说这是不可能的,它只能存储0到255之间的值。当
Next
语句尝试将其从255递增到256时,则为Kaboom。
Simply declare them As Integer
. 只需将它们声明
As Integer
。 It not only solves the overflow problem, it is also faster. 它不仅解决了溢出问题,而且速度更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.