以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  未设置对象变量或 With 块变量  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=92783)

--  作者:刘林
--  发布时间:2016/11/12 22:09:00
--  未设置对象变量或 With 块变量
Dim dlg As new OpenFileDialog
dlg.Filter = "Excel|*.xls;*.xlsx"
If dlg.ShowDialog = DialogResult.OK Then
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Dim bmh As Integer
    Dim ksh As Integer
    Dim xm As Integer
    Dim sw As Integer
    Dim dl As Integer
    Dim njdm As Integer
    Dim bj As Integer
    Dim xxmc As Integer
    For i As Integer = 0 To sheet.Cols.count -1
        If sheet(0,i).value = "报名号"
            bmh =i
        End If
        If sheet(0,i).value = "考试号"
            ksh = i
        End If
        If sheet(0,i).value = "姓名"
            xm = i
        End If
        If sheet(0,i).value ="生物_A"
            sw = i
        End If
        If sheet(0,i).value ="地理_B"
            dl = i
        End If
        If sheet(0,i).value ="年级代码"
            njdm = i
        End If
        If sheet(0,i).value ="班级"
            bj = i
        End If
        If sheet(0,i).value = "单位名称"
            xxmc = i
        End If
    Next
    Tables("成绩").StopRedraw()
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim bmh1 As String = sheet(n,bmh).value.replace(" ","").replace(chr(9),"")
        Dim xm1 As String = sheet(n,xm).value.replace(" ","").replace(chr(9),"")
        Dim bj1 As String = sheet(n,bj).value.replace(" ","").replace(chr(9),"")
        Dim njdm1 As String = sheet(n,njdm).value.replace(" ","").replace(chr(9),"")
        Dim xxmc1 As String = sheet(n,xxmc).value.replace(" ","").replace(chr(9),"")
        Dim ksmc As String = e.Form.controls("combobox2").value
        \'\'\'\' MessageBox.show(bmh1 & xm1 & bj1 & njdm1 & ksmc & xxmc1,"提示")
        Dim dr As DataRow = DataTables("成绩").sqlFind("单位名称 = \'" & xxmc1 & "\'and 姓名 = \'" & xm1 & "\'And 考试名称 = \'" & ksmc & "\' And 年级代码 = \'" & njdm1 & "\' And 班级 = \'" & bj1 & "\'")
        For m As Integer = 0 To sheet.Cols.count -1
            If dr Is Nothing Then 
                dr(sheet(0,m).value) = Sheet(n,m).Value

            Else
 Continue For
             End If
        Next  
    Next
    Tables("成绩").ResumeRedraw()
    
End If


请问老师上面代码是用EXCl 导入生物,地理成绩,注:如果找到符合条件的就把生物、地理成绩导入进行成绩表,否则不增加,再找下一个,出现:未设置对象变量或 With 块变量



--  作者:有点色
--  发布时间:2016/11/13 9:49:00
--  

sqlFind找不到对应的行,就会报错。

 

            If dr IsNot Nothing Then 
                 dr(sheet(0,m).value) = Sheet(n,m).Value
            Else
                 Continue For
            End If

 


--  作者:刘林
--  发布时间:2016/11/13 9:58:00
--  
哦,太不好意思了没注意,谢谢
--  作者:刘林
--  发布时间:2016/11/13 10:08:00
--  
对了,老师,不过我觉得较慢,上面代码能不能优化提高速度
--  作者:有点色
--  发布时间:2016/11/13 10:51:00
--  

 sqlfind,尽量改成find。

 

 如果还要提交效率,要这样处理

 

下载信息  [文件大小:31.3 KB  下载次数:7]
图片点击可在新窗口打开查看点击浏览该文件:导入excel文件.zip