我的程序在vb工程中能够运行,但是生成的.exe文件就是不能运行
显示错误是unknow software exception 我查找不错是那点代码
的问题,请大家帮忙看看
当程序运行时的报错是:0×6a2a50e3指令引用的“0×00000008“内存,改内存不能为”read“
单击确定后的信息是:”0×01ff02df“指令引用的“0×b801ff7f”内存,改内存不能为“written”终止单击“确定”
Private Sub CurtButton6_Click()Dim tel As String
If Combo4.Text = "并且" Then
tel = "and"
End If
If Combo4.Text = "或者" Then
tel = "or"
End IfDim conn As New ADODB.Connection
Dim connstr As Stringconnstr = "driver={sql server};server=(local);uid=sa;pwd=200110;database=hq"
conn.Open connstr
Dim strSource, strDestination As String
Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook
Dim xlsheet As New Excel.Worksheet
xlapp.Visible = False
Dim rs As New ADODB.Recordset
If Combo2.Text = "" And Combo6.Text = "" Then
Sql = "select * from 数据录入_评估成绩 where 士兵登记表号 in (select 士兵登记表号 from 数据录入_士兵基本情况 where " & Combo1.Text & " like '%" & Combo3.Text & "%')"
rs.Open Sql, conn, 3, 2
Else
Sql = "select * from 评估成绩 where 登记表号 in (select 登记表号 from 基本情况 where " & Combo1.Text & " like '%" & Combo3.Text & "%' " & tel & " " & Combo2.Text & " like '%" & Combo6.Text & "%')"
rs.Open Sql, conn, 3, 2
End If
' dv = Chr(10)
'Dim l As Integer
'While Not rs8.EOF
' If l < 100000 Then
' l = l + 1
' End If
' ctGrid1.AddItem rs8!姓名 & dv & rs8!单位名称 rs8.MoveNext
'Wend
Set xlapp = CreateObject("Excel.Application")
'激活EXCEL应用程序
' xlapp.Visible = False '隐藏EXCEL应用程序窗口
' Dim strSource, strDestination As String
strSource = App.Path & "\Excels\RegisterFee.xls"
'RegisterFee.xls就是一个模版文件
strDestination = "e:\" & Text1.Text & ".xls" FileCopy strSource, strDestination
'将模版文件拷贝到一个临时文件
Set xlbook = xlapp.Workbooks.Open(strDestination)
'打开工作簿,strDestination为一个EXCEL报表文件
Set xlsheet = xlbook.Worksheets(1)
rs.MoveFirst
' datPrimaryRS为Data控件
curnum = 3
Dim i As Integer
Do While Not rs.EOF
If i < 100000 Then
i = i + 1
End If
With xlsheet
.Cells(curnum, 1).NumberFormatLocal = "@"
.Cells(curnum, 2).NumberFormatLocal = "@"
.Cells(curnum, 3).NumberFormatLocal = "@"
.Cells(curnum, 1) = rs!姓名
.Cells(curnum, 2) = rs!单位名称
.Cells(curnum, 3) = i
End With
curnum = curnum + 1
rs.MoveNext
If rs.EOF Then
Exit Do
End If
Loop xlbook.Save '保存文件
' xlsheet.PrintOut '执行打印
xlapp.Quit '退出EXCEL
Set xlapp = Nothing
rs.Close
Set rs = Nothing
MsgBox "打印完成!"
If Text1.Text = "" Then
MsgBox "文件名称不能为空!"
Text1.SetFocus
Exit Sub
End IfEnd Sub
显示错误是unknow software exception 我查找不错是那点代码
的问题,请大家帮忙看看
当程序运行时的报错是:0×6a2a50e3指令引用的“0×00000008“内存,改内存不能为”read“
单击确定后的信息是:”0×01ff02df“指令引用的“0×b801ff7f”内存,改内存不能为“written”终止单击“确定”
Private Sub CurtButton6_Click()Dim tel As String
If Combo4.Text = "并且" Then
tel = "and"
End If
If Combo4.Text = "或者" Then
tel = "or"
End IfDim conn As New ADODB.Connection
Dim connstr As Stringconnstr = "driver={sql server};server=(local);uid=sa;pwd=200110;database=hq"
conn.Open connstr
Dim strSource, strDestination As String
Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook
Dim xlsheet As New Excel.Worksheet
xlapp.Visible = False
Dim rs As New ADODB.Recordset
If Combo2.Text = "" And Combo6.Text = "" Then
Sql = "select * from 数据录入_评估成绩 where 士兵登记表号 in (select 士兵登记表号 from 数据录入_士兵基本情况 where " & Combo1.Text & " like '%" & Combo3.Text & "%')"
rs.Open Sql, conn, 3, 2
Else
Sql = "select * from 评估成绩 where 登记表号 in (select 登记表号 from 基本情况 where " & Combo1.Text & " like '%" & Combo3.Text & "%' " & tel & " " & Combo2.Text & " like '%" & Combo6.Text & "%')"
rs.Open Sql, conn, 3, 2
End If
' dv = Chr(10)
'Dim l As Integer
'While Not rs8.EOF
' If l < 100000 Then
' l = l + 1
' End If
' ctGrid1.AddItem rs8!姓名 & dv & rs8!单位名称 rs8.MoveNext
'Wend
Set xlapp = CreateObject("Excel.Application")
'激活EXCEL应用程序
' xlapp.Visible = False '隐藏EXCEL应用程序窗口
' Dim strSource, strDestination As String
strSource = App.Path & "\Excels\RegisterFee.xls"
'RegisterFee.xls就是一个模版文件
strDestination = "e:\" & Text1.Text & ".xls" FileCopy strSource, strDestination
'将模版文件拷贝到一个临时文件
Set xlbook = xlapp.Workbooks.Open(strDestination)
'打开工作簿,strDestination为一个EXCEL报表文件
Set xlsheet = xlbook.Worksheets(1)
rs.MoveFirst
' datPrimaryRS为Data控件
curnum = 3
Dim i As Integer
Do While Not rs.EOF
If i < 100000 Then
i = i + 1
End If
With xlsheet
.Cells(curnum, 1).NumberFormatLocal = "@"
.Cells(curnum, 2).NumberFormatLocal = "@"
.Cells(curnum, 3).NumberFormatLocal = "@"
.Cells(curnum, 1) = rs!姓名
.Cells(curnum, 2) = rs!单位名称
.Cells(curnum, 3) = i
End With
curnum = curnum + 1
rs.MoveNext
If rs.EOF Then
Exit Do
End If
Loop xlbook.Save '保存文件
' xlsheet.PrintOut '执行打印
xlapp.Quit '退出EXCEL
Set xlapp = Nothing
rs.Close
Set rs = Nothing
MsgBox "打印完成!"
If Text1.Text = "" Then
MsgBox "文件名称不能为空!"
Text1.SetFocus
Exit Sub
End IfEnd Sub
请将一下程序代码:
If Combo2.Text = "" And Combo6.Text = "" Then
Sql = "select * from 数据录入_评估成绩 where 士兵登记表号 in (select 士兵登记表号 from 数据录入_士兵基本情况 where " & Combo1.Text & " like '%" & Combo3.Text & "%')"
rs.Open Sql, conn, 3, 2
改为:If Combo2.Text = "" And Combo6.Text = "" Then
Sql = "select * from 评估成绩 where 登记表号 in (select 登记表号 from 基本情况 where " & Combo1.Text & " like '%" & Combo3.Text & "%')"
rs.Open Sql, conn, 3, 2
单击确定后的信息是:”0×01ff02df“指令引用的“0×b801ff7f”内存,改内存不能为“written”终止单击“确定”--调用对象出错。检查你用到了什么对象,而又没有预先考虑该对象如果在系统中不存在的情况下捕捉该错误。比如我们用到printer对象,而电脑又没有装打印机驱动,该错误就出现。(98系统一般不报错,XP系统经常报错(xp系统连你写错的但没有用到的变量也会报该错误))
--如果确实在程序中找不到语法错误,请在程序中加 On Error Resume Next ,强制执行,至少不会看到一运行.exe就死掉。
'RegisterFee.xls就是一个模版文件
strDestination = "e:\" & Text1.Text & ".xls"
不就用到了路径了吗?好好检查哦。
strSource就是e:\\Excels\RegisterFee.xls了,app不是处于根目录下则没有问题。
还有问一下If Text1.Text = "" Then
MsgBox "文件名称不能为空!"
Text1.SetFocus
Exit Sub
End If这种校验不是应该在前面做的么,为什么放到最后呢,能起作用吗?
问题出在VB程序对APP.PATH处理的Bug上,解决办法是打补丁或用一个绝对路径代替“APP.PATH”;
http://www.microsoft.com/downloads/details.aspx?FamilyID=8ECEC2B4-9118-4A63-8DBD-B34547AD2C62&displaylang=zh-cn#filelist