我写了一段代码,运行时出现:"错误提示6 :溢出"
Private Sub Command1_Click()
Dim a As Integer 'Single
Dim b As IntegerT7 = 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 :溢出"
所学不精,请大家帮我改一下,谢谢.
 

解决方案 »

  1.   

    去掉Val(),直接用CLNG看看.VB默认类型是INTEGER.
      

  2.   

    去掉Val(),直接用CLNG后,在Text7中输入了一个数,再点Command1:
    出现错误:"实时错误,类型不匹配"错误语句仍为:a = CLng(Text8.Text) / CLng(Text7.Text)
      

  3.   

    dim a as long
    dim b as long
      

  4.   

    楼主定义的是16位的Integer,使用时却当32位的Long,难怪会溢出
    Dim a As Integer
    Dim b As Integera = CLng(Val(Text8.Text)) / CLng(Val(Text7.Text))
      

  5.   

    你的出错在于CLng不能转换非数字字符串,可先判断textbox中的数据是否为数字再进行运算。
    If IsNumeric(Text8) And IsNumeric(Text7) Then
       a = CLng(Text8.Text) / CLng(Text7.Text)
    End If
      

  6.   

    '分母不要加CLng了,这样可以提高运算的速度: 
    Dim a As Long
    Dim b As Long.........a = CLng(Text8.Text) / Val(Text7.Text) '______就是这名出错.........
      

  7.   

    或者这样也行:Dim a As Integer
    Dim b As Integer
    Dim 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'.........