以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  调用的目标发生了异常  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=92511)

--  作者:zhuxin
--  发布时间:2016/11/5 11:53:00
--  调用的目标发生了异常


图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看
提示:调用的目标发生了异常,试图除以零。

 


图片点击可在新窗口打开查看此主题相关图片如下:2.png
图片点击可在新窗口打开查看

--  作者:zhuxin
--  发布时间:2016/11/5 11:57:00
--  

这个不知怎样解决,检查了很多次都不知哪里出错了

If e.DataCol.Name = "产品名称" Then
    Dim dr As DataRow = e.DataRow
    Dim dt As DataTable = DataTables("周转卡明细")
    Dim frm As WinForm.Form = Forms("损耗率计算")
    If frm.Opened Then
        Dim d1 = frm.Controls("DateTimePicker1").value
        Dim d2 = frm.Controls("DateTimePicker2").value
        If d1 IsNot Nothing And d2 IsNot Nothing
            dr("压铸") = dt.Compute("Sum(压铸良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控1良品数") = dt.Compute("Sum(数控1良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控2良品数") = dt.Compute("Sum(数控2良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控3良品数") = dt.Compute("Sum(数控3良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加1良品数") = dt.Compute("Sum(机加1良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加2良品数") = dt.Compute("Sum(机加2良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加3良品数") = dt.Compute("Sum(机加3良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加4良品数") = dt.Compute("Sum(机加4良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加5良品数") = dt.Compute("Sum(机加5良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加6良品数") = dt.Compute("Sum(机加6良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加7良品数") = dt.Compute("Sum(机加7良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加8良品数") = dt.Compute("Sum(机加8良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加9良品数") = dt.Compute("Sum(机加9良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加10良品数") = dt.Compute("Sum(机加10良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("毛刺良品数") = dt.Compute("Sum(毛刺良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("抛光良品数") = dt.Compute("Sum(抛光良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("震光良品数") = dt.Compute("Sum(震光良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("品管良品数") = dt.Compute("Sum(品管良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("仓库良品数") = dt.Compute("Sum(仓库良品数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("压铸不良数") = dt.Compute("Sum(压铸不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控1不良数") = dt.Compute("Sum(数控1不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控2不良数") = dt.Compute("Sum(数控2不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控3不良数") = dt.Compute("Sum(数控3不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控4不良数") = dt.Compute("Sum(数控4不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加1不良数") = dt.Compute("Sum(机加1不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加2不良数") = dt.Compute("Sum(机加2不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加3不良数") = dt.Compute("Sum(机加3不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加4不良数") = dt.Compute("Sum(机加4不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加5不良数") = dt.Compute("Sum(机加5不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加6不良数") = dt.Compute("Sum(机加6不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加7不良数") = dt.Compute("Sum(机加7不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加8不良数") = dt.Compute("Sum(机加8不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加9不良数") = dt.Compute("Sum(机加9不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("机加10不良数") = dt.Compute("Sum(机加10不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("毛刺不良数") = dt.Compute("Sum(毛刺不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("抛光不良数") = dt.Compute("Sum(抛光不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("震光不良数") = dt.Compute("Sum(震光不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("品管不良数") = dt.Compute("Sum(品管不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("仓库不良数") = dt.Compute("Sum(仓库不良数)","[产品名称] = \'" & dr("产品名称") & "\' and 日期 >= \'" & d1 & "\' and 日期 <= \'" & d2 & "\' ")
            dr("数控耗损") = dr("数控1不良数") + dr("数控2不良数") + dr("数控3不良数") + dr("数控4不良数")
            dr("机加耗损") = dr("机加1不良数") + dr("机加2不良数") + dr("机加3不良数") + dr("机加4不良数")  + dr("机加5不良数") + dr("机加6不良数") + dr("机加7不良数") + dr("机加8不良数")  + dr("机加9不良数") + dr("机加10不良数")
            dr("毛刺耗损") = dr("毛刺不良数")
            dr("总耗损") = dr("数控耗损") + dr("机加耗损") + dr("毛刺耗损") + dr("抛光不良数") + dr("震光不良数") + dr("品管不良数") + dr("仓库不良数")
            If dr("数控耗损") = 0 Or  dr("数控1良品数") + dr("数控1不良数")  = 0 Then
                dr("数控良品率") = ""
            Else
                dr("数控良品率") = dr("数控耗损") / (dr("数控1良品数") + dr("数控1不良数") )
            End If
            If dr("机加耗损") = 0 Or dr("机加1不良数") + dr("机加1良品数") = 0 Then
                dr("机加良品率") = ""
            Else
                dr("机加良品率") = dr("机加耗损") / (dr("机加1不良数") + dr("机加1良品数") )
            End If
           
            If dr("毛刺耗损") = 0  Or dr("毛刺耗损") + dr("毛刺良品数")  Then
                dr("毛刺不良率") = ""
            Else
                dr("毛刺不良率") = dr("毛刺耗损") / (dr("毛刺耗损") + dr("毛刺良品数") )
            End If
            If dr("抛光不良数") = 0 Or dr("抛光不良数") + dr("抛光良品数")  Then
                dr("抛光不良率") = ""
            Else
                dr("抛光不良率") = dr("抛光不良数") / (dr("抛光不良数") + dr("抛光良品数") )
            End If
            If dr("品管不良数") = 0 Or dr("品管不良数") + dr("品管良品数")  Then
                dr("品管良品率") = ""
            Else
                dr("品管良品率") = dr("品管不良数") / (dr("品管不良数") + dr("品管良品数") )
            End If
            If dr("压铸") IsNot Nothing Then
                If (dr("压铸") - dr("仓库良品数") )  = 0 Then
                    dr("报废率") = ""
                Else
                    dr("报废率") = (dr("压铸") - dr("仓库良品数") ) / dr("压铸")
                End If
            ElseIf dr("数控1良品数") IsNot Nothing Then
                If (dr("数控1良品数") - dr("仓库良品数") ) = 0 Then
                    dr("报废率") = ""
                Else
                    dr("报废率") = (dr("数控1良品数") - dr("仓库良品数") ) / dr("数控1良品数")
                End If
          


--  作者:zhuxin
--  发布时间:2016/11/5 11:58:00
--  
  ElseIf dr("机加1良品数") IsNot Nothing Then
                If (dr("机加1良品数") - dr("仓库良品数") )  = 0 Then
                    dr("报废率") = ""
                Else
                    dr("报废率") = (dr("机加1良品数") - dr("仓库良品数") ) / dr("机加1良品数")
                End If
            ElseIf dr("毛刺良品数") IsNot Nothing Then
                If (dr("毛刺良品数") - dr("仓库良品数") )   = 0 Then
                    dr("报废率") = ""
                Else
                    dr("报废率") = (dr("毛刺良品数") - dr("仓库良品数") ) / dr("毛刺良品数")
                End If
            Else
                If  dr("抛光良品数") - dr("仓库良品数") = 0 Or  dr("抛光良品数") = "" Then
                    dr("报废率") = ""
                Else
                    dr("报废率") = (dr("抛光良品数") - dr("仓库良品数") ) / dr("抛光良品数")
                End If
            End If
        End If
    Else
        dr("压铸") = dt.Compute("Sum(压铸良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("数控1良品数") = dt.Compute("Sum(数控1良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("数控2良品数") = dt.Compute("Sum(数控2良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("数控3良品数") = dt.Compute("Sum(数控3良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加1良品数") = dt.Compute("Sum(机加1良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加2良品数") = dt.Compute("Sum(机加2良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加3良品数") = dt.Compute("Sum(机加3良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加4良品数") = dt.Compute("Sum(机加4良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加5良品数") = dt.Compute("Sum(机加5良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加6良品数") = dt.Compute("Sum(机加6良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加7良品数") = dt.Compute("Sum(机加7良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加8良品数") = dt.Compute("Sum(机加8良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加9良品数") = dt.Compute("Sum(机加9良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加10良品数") = dt.Compute("Sum(机加10良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("毛刺良品数") = dt.Compute("Sum(毛刺良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("抛光良品数") = dt.Compute("Sum(抛光良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("震光良品数") = dt.Compute("Sum(震光良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("品管良品数") = dt.Compute("Sum(品管良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("仓库良品数") = dt.Compute("Sum(仓库良品数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("压铸不良数") = dt.Compute("Sum(压铸不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("数控1不良数") = dt.Compute("Sum(数控1不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("数控2不良数") = dt.Compute("Sum(数控2不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("数控3不良数") = dt.Compute("Sum(数控3不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("数控4不良数") = dt.Compute("Sum(数控4不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加1不良数") = dt.Compute("Sum(机加1不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加2不良数") = dt.Compute("Sum(机加2不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加3不良数") = dt.Compute("Sum(机加3不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加4不良数") = dt.Compute("Sum(机加4不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加5不良数") = dt.Compute("Sum(机加5不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加6不良数") = dt.Compute("Sum(机加6不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加7不良数") = dt.Compute("Sum(机加7不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加8不良数") = dt.Compute("Sum(机加8不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加9不良数") = dt.Compute("Sum(机加9不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("机加10不良数") = dt.Compute("Sum(机加10不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("毛刺不良数") = dt.Compute("Sum(毛刺不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("抛光不良数") = dt.Compute("Sum(抛光不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("震光不良数") = dt.Compute("Sum(震光不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("品管不良数") = dt.Compute("Sum(品管不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
        dr("仓库不良数") = dt.Compute("Sum(仓库不良数)","[产品名称] = \'" & dr("产品名称") & "\'")
    End If
End If

--  作者:有点蓝
--  发布时间:2016/11/5 14:15:00
--  
提示很明显了,除数不能为0

类似这样的代码, dr("数控耗损") / (dr("数控1良品数") + dr("数控1不良数") )

除号“/”后面的计算值不能为0,这种数据的问题只能靠自己查找了

--  作者:zhuxin
--  发布时间:2016/11/5 14:35:00
--  

改了一种方式假设条件现在可以了