以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  表datacolchanged报错  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=132375)

--  作者:deliangzhaoe
--  发布时间:2019/3/20 19:08:00
--  表datacolchanged报错
表中无行时,新增一行报错两次:
.NET Framework 版本:2.0.50727.5420
Foxtable 版本:2018.10.9.1
错误所在事件:表,安全费用使用,DataColChanged
详细错误信息:
调用的目标发生了异常。
未将对象引用设置到对象的实例。

DataColChanged事件:
\'修改日期列时,年度月度可根据日期列自动修改
If e.DataCol.name = "日期" Then
    If e.DataRow.IsNull("日期") Then \'是否为空
        e.DataRow("月度") = Nothing \'如果为空,则月度为空
        e.DataRow("年度") = Nothing
    Else
        e.DataRow("月度") = month(e.DataRow("日期"))
        e.DataRow("年度") = year(e.DataRow("日期"))
    End If
End If

\'上月余额
Select Case e.DataCol.name
    Case "企业名称"
        If e.DataRow.IsNull("企业名称") Then
            e.DataRow("上月余额") = Nothing
        Else
            Dim fdr As DataRow = e.DataTable.find("年度 = \'" & e.DataRow("年度") - 1 & "\' and 月度 = \'12\' and 企业名称 = \'" & e.DataRow("企业名称") & "\'","本月余额",0)
            Dim fdr1 As DataRow = e.DataTable.find("月度 = \'" & e.DataRow("月度") - 1 & "\' And 年度 =  \'" & e.DataRow("年度") & "\' and 企业名称 = \'" & e.DataRow("企业名称") & "\'","本月余额",0)
            If e.DataRow("月度") = "1"  Then
                If fdr IsNot Nothing Then
                    e.DataRow("上月余额") =  fdr("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            ElseIf e.DataRow("月度") > "1"  Then
                If fdr1 IsNot Nothing Then
                    e.DataRow("上月余额") =fdr1("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            End If
        End If
    Case "日期"
        If e.DataRow.IsNull("日期") Then
            e.DataRow("上月余额") = Nothing
        Else
            Dim fdr As DataRow = e.DataTable.find("年度 = \'" & e.DataRow("年度") - 1 & "\' and 月度 = \'12\' and 企业名称 = \'" & e.DataRow("企业名称") & "\'","本月余额",0)
            Dim fdr1 As DataRow = e.DataTable.find("月度 = \'" & e.DataRow("月度") - 1 & "\' And 年度 =  \'" & e.DataRow("年度") & "\' and 企业名称 = \'" & e.DataRow("企业名称") & "\'","本月余额",0)
            If e.DataRow("月度") = "1"  Then
                If fdr IsNot Nothing Then
                    e.DataRow("上月余额") =  fdr("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            ElseIf e.DataRow("月度") > "1"  Then
                If fdr1 IsNot Nothing Then
                    e.DataRow("上月余额") =fdr1("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            End If
        End If
End Select

\'本月应提额
Select Case e.DataCol.name
    Case "企业名称"
        If e.DataRow.IsNull("企业名称") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = \'" & Tables("安全费用使用").current ("企业名称") & "\' And 年度 =  \'"& Tables("安全费用使用").current ("年度") &"\'")
            If r1 IsNot Nothing Then
                e.DataRow("本月应提额") = r1("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If
    Case "日期"
        If e.DataRow.IsNull("日期") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = \'" & Tables("安全费用使用").current ("企业名称") & "\' And 年度 =  \'"& Tables("安全费用使用").current ("年度") &"\'")
            If r1 IsNot Nothing Then
                e.DataRow("本月应提额") = r1("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If
End Select


\'本月支出额
If e.DataCol.name = "数量" Then
    If e.DataRow.IsNull("数量") Then \'是否为空
        e.DataRow("本月支出额") = Nothing \'如果为空,则为空
    Else
        e.DataRow("本月支出额") = DataTables("安全费用使用").Compute("Sum(金额)","月度 = \'" & e.DataRow("月度") & "\' And 年度 = \'" & e.DataRow("年度") & "\' and 企业名称 = \'" & e.DataRow("企业名称") & "\'")
    End If
End If

\'按照企业名称和日期列排序
If e.DataCol.name = "数量" Then
    If e.DataRow IsNot Nothing Then \'不为空
        Tables("安全费用使用").Sort = "企业名称,日期"  \'按企业名称和日期排序
    Else
    End If
End If

请老师帮忙看一下,代码哪里有问题。谢谢!


--  作者:有点甜
--  发布时间:2019/3/20 21:59:00
--  

看看是不是这句代码报错

 

Tables("安全费用使用").Sort = "企业名称,日期"  \'按企业名称和日期排序

 

学会调试定位出错位置 http://www.foxtable.com/webhelp/scr/1485.htm

 


--  作者:deliangzhaoe
--  发布时间:2019/3/23 14:23:00
--  
datacolchanged事件中这段代码有问题:
\'本月应提额
Select Case e.DataCol.name
    Case "企业名称"
        If e.DataRow.IsNull("企业名称") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = \'" & Tables("安全费用使用").current ("企业名称") & "\' And 年度 =  \'"& Tables("安全费用使用").current ("年度") &"\'")
            If r1 IsNot Nothing Then
                e.DataRow("本月应提额") = r1("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If

    Case "日期"
        If e.DataRow.IsNull("日期") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r2 As DataRow = DataTables("安全费用提取").find("企业名称 = \'" & Tables("安全费用使用").current ("企业名称") & "\' And 年度 =  \'"& Tables("安全费用使用").current ("年度") &"\'")
            If r2 IsNot Nothing Then
                e.DataRow("本月应提额") = r2("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If
End Select
请老师帮忙看一下。表中无行时,新增一行报错。表中已有行,新增一行时正常。日期列自动填入今天日期,企业名称自动填入当前登录者的所在分组。

[此贴子已经被作者于2019/3/23 14:25:21编辑过]

--  作者:有点蓝
--  发布时间:2019/3/23 14:45:00
--  
Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = \'" & e.DataRow ("企业名称") & "\' And 年度 =  \'"& e.DataRow("年度") &"\'")

或者

if Tables("安全费用使用").current isnot nothing then
    Dim r2 As DataRow = DataTables("安全费用提取").find("企业名称 = \'" & Tables("安全费用使用").current ("企业名称") & "\' And 年度 =  \'"& Tables("安全费用使用").current ("年度") &"\'")
            If r2 IsNot Nothing Then
                e.DataRow("本月应提额") = r2("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
end if