以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]运行错误“未设置对象变量或 With 块变量。” 不知道原因  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=174629)

--  作者:pursat88
--  发布时间:2022/1/24 11:34:00
--  [求助]运行错误“未设置对象变量或 With 块变量。” 不知道原因
那个红色代码执行时候出现《未设置对象变量或 With 块变量。》运行错误不知道原因。

Dim sfzh As Boolean = False \'是否选择了身份证号
Dim sfzbs As Boolean = False \'是否选择了身份标识
Dim Book As New XLS.Book \'定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表

Dim h As Integer =0
Dim s As Integer = 1
For Each dc As DataRow In DataTables("基本信息").DataRows \'基本信息的所有人的身份标识符遍历
  Dim sfbsf As String  = dc("身份标识符")
    If h = 0 Then
        Sheet(0,0).Value = "姓名"
        If e.Form.Controls("CheckBox1").Checked Then
            Sheet(0,s).Value = "身份证号"
            s =s + 1
        End If
        If e.Form.Controls("CheckBox2").Checked Then
            Sheet(0,s).Value = "身份标识"
            s =s + 1
        End If
        For Each r As Row In Tables("表的表").GetCheckedRows
            Sheet(0,s).Value = r("表名称")
            s = s + 1
        Next
        
    End If
    s = 0
    
    
    Sheet(h + 1,s).Value = dc("姓名")
    \'Sheet(h + 1,s).Value = "1"
    s = s + 1
    If e.Form.Controls("CheckBox1").Checked Then
        Sheet(h + 1,s).Value = dc("身份证号")
        s =s + 1
    End If
    If e.Form.Controls("CheckBox2").Checked Then
        Sheet(h + 1,s).Value = dc("身份标识符")
        s =s + 1
    End If
    For Each r As Row In Tables("表的表").GetCheckedRows
        Dim dr As DataRow  
        \'dr = DataTables( r("表名称")).Find( "身份标识符 =  \'E7F7620C0715A88\'")
        dr = DataTables( r("表名称")).Find( "身份标识符 =  \'" & dc("身份标识符") & "\'")
        Sheet(h + 1,s).Value =dr(r("表名称"))
        \'MessageBox.Show(dc("身份标识符"))
    Next
    h = h +1
Next

--  作者:有点蓝
--  发布时间:2022/1/24 11:48:00
--  
    For Each r As Row In Tables("表的表").GetCheckedRows
        Dim dr As DataRow  
        \'dr = DataTables( r("表名称")).Find( "身份标识符 =  \'E7F7620C0715A88\'")
msgbox(r("表名称")) 有这个名称的表吗?
        dr = DataTables( r("表名称")).Find( "身份标识符 =  \'" & dc("身份标识符") & "\'")
if dr isnot nothing then 没有判断是否有查询结果:http://www.foxtable.com/webhelp/topics/0396.htm,看示例三
        Sheet(h + 1,s).Value =dr(r("表名称")) 
        \'MessageBox.Show(dc("身份标识符"))
end if
    Next

--  作者:pursat88
--  发布时间:2022/1/24 12:35:00
--  
解决了,谢谢老师。
[此贴子已经被作者于2022/1/24 12:38:59编辑过]