|
发表于 25-1-2009 01:32 PM
|
显示全部楼层
这好像是vb6的bug。。。
如果你的计算中,第一和第二或者之后的都是integer type(16 bits),那么计算结果也是integer type。。。所以,20000 + 20000 = 40000,就出现overflow。。。最后,vb 返回给 a 的答案就是 overflow。。。- Private Sub Form_Load()
- On Error GoTo myerror
- Dim a As Long
- a = 32767 + 1 '= 32768 (+ve integer limit, overflow error)
- a = 32768 + 1 '= 32769 (ok, because the 1st parameter already long type)
- a = 32767& + 1 '= 32768 (ok, because we force the 1st parameter to long type)
- a = 32767 + CLng(1) '= 32768 (ok, because we force the 2nd parameter to long type)
- a = 32766 - 1 + 2 '(ok)
- a = 32766 + 2 - 1 'Overflow error
- 'Overflow, because 32766 + 2 > 32767, even
- 'the above calculation also result in 32767
- Exit Sub
- myerror:
- MsgBox "Runtime error!!!, " & Err.Description
- Resume Next
- End Sub
复制代码 |
|