首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

:程序运行"异常提示6 :溢出"

2012-01-19 
请高手看看:程序运行"错误提示6 :溢出"我写了一段代码,运行时出现:"错误提示6 :溢出"Private Sub Command1

请高手看看:程序运行"错误提示6 :溢出"
我写了一段代码,运行时出现:"错误提示6 :溢出"
Private Sub Command1_Click()
Dim a As Integer 'Single
Dim b As Integer

T7 = Val(Text7.Text)
T8 = Val(Text8.Text)
T9 = Val(Text9.Text)
T10 = Val(Text10.Text)
T11 = Val(Text11.Text)
T12 = Val(Text12.Text)

If Text7 = "" Then
  MsgBox "住院费用 不能为空! ", vbSystemModal, "提示"
  Text7.SetFocus
ElseIf Text7 <> "" Then
  a = CLng(Val(Text8.Text)) / CLng(Val(Text7.Text))______就是这名出错  
ElseIf T8 > T7 Then '判断报销费用是否小于或等于住院费用.
  MsgBox "住院费用 小于 总报销额: 请重新输入! ", vbSystemModal, "提示"
  Text7.Text = ""
  Text8.Text = ""
  Text7.SetFocus
ElseIf T8 <> T9 + T10 + T11 + T12 Then '判断分项报销费用是否等于总报销费用.
  MsgBox "分项报销额不等于总报销额: 请重新输入! ", vbSystemModal, "提示" 'Trim(Text8.Text) <> Trim(Text9.Text) + Trim(Text10.Text) + Trim(Text11.Text) + Trim(Text12.Text)
  Text9.Text = ""
  Text10.Text = ""
  Text11.Text = ""
  Text12.Text = ""
  Text9.SetFocus
ElseIf a < 0.2 Then
  b = MsgBox(" 报销率低于20% : 是否返回修改数据 ? ", vbOKCancel, "提示")
  If b = 1 Then
  Text7.SetFocus
  Else
   
   
   
   
  MsgBox "数据保存成功!", vbSystemModal, "提示"
   
  '将输入转换小写字母
  Call SetCapsLock(False)
  Call SetNumLock(True) '打开NumLock键
   
  Command2.SetFocus
  End If
  Else
  End If
End Sub

运行程序时,如果正确输入各项数据后,点击Command1,不出问题;如果不输入任何数据,点击Command1,也出现:
"错误提示6 :溢出"
所学不精,请大家帮我改一下,谢谢.


[解决办法]
楼主定义的是16位的Integer,使用时却当32位的Long,难怪会溢出

VB code
Dim a As IntegerDim b As Integera = CLng(Val(Text8.Text)) / CLng(Val(Text7.Text))
[解决办法]
探讨
去掉Val(),直接用CLNG后,在Text7中输入了一个数,再点Command1:
出现错误:"实时错误,类型不匹配"

错误语句仍为:a = CLng(Text8.Text) / CLng(Text7.Text)

[解决办法]
VB code
'分母不要加CLng了,这样可以提高运算的速度: Dim a As LongDim b As Long.........a = CLng(Text8.Text) / Val(Text7.Text) '______就是这名出错.........
[解决办法]
或者这样也行:

VB code
Dim a As IntegerDim b As IntegerDim m As Double'.........m = CDbl(Text8.Text) / Val(Text7.Text)If m > -32768 And m < 32768 Then   a = m 'CLng(Val(Text8.Text)) / CLng(Val(Text7.Text))______就是这名出错   MsgBox ("a=" & a)Else   MsgBox (m & "超出范围了,重来!")End If'......... 

热点排行