文件的操作

chuying 2003-03-09 06:54:59
Open "c:\11.txt" For Output As #1
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
aa(i) = rs.Fields("ITEM_CODE")
bb(i) = rs.Fields("SAMPLING_TIME")
cc(i) = rs.Fields("VALUEA")
rs.MoveNext

Print #1, aa(i)
Print #1, bb(i)
Print #1, cc(i)
' Print #1, TxtPW1.Text
' Print #1, TxtPW2.Text
Next i

Close #1
我把这个文件打开以后进行写操作没有什么问题,如果对它每隔一小时进行一次进行操作,循环进行,出现错误提示:“文件已经打开”,是什么原因呢???
...全文
79 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2003-03-10
  • 打赏
  • 举报
回复
try:

cnn.Close------->set rs=nothing:set cnn=nothing
chuying 2003-03-09
  • 打赏
  • 举报
回复
数据库打开以后一直进行操作,
下面是代码:
Private Sub Command5_Click()
Dim i As Integer
dt = DateValue(Date) + TimeValue("1998-04-01 00:00:00")
Dim strsql As String
Dim yy As String
Dim mm As String
Dim dd As String
yy = Year(dt)
mm = Month(dt)
dd = Day(dt)
cnn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=monitor;Data Source=dlemc"
cnn.Open
strsql = "select * from SAMPLE_RESULT_DETAIL2 where station_code='" & 2 & "' and year(sampling_time)='" & yy & "' and month(sampling_time)='" & mm & "' and day(sampling_time)='" & dd & "' "
'strsql = "select * from SAMPLE_RESULT_DETAIL2 " 'where station_code='" & 9 & "' and year(sampling_time)=2003 and month(sampling_time)=2 and day(sampling_time)=12"
rs.ActiveConnection = cnn
rs.CursorType = adOpenKeyset
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open strsql
Set DataGrid1.DataSource = rs
'rs.Delete
Open "c:\11.txt" For Output As #1
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
aa(i) = rs.Fields("ITEM_CODE")
bb(i) = rs.Fields("SAMPLING_TIME")
cc(i) = rs.Fields("VALUEA")
rs.MoveNext

Print #1, aa(i)
Print #1, bb(i)
Print #1, cc(i)
Next i
Close #1
cnn.Close
End Sub
。。。。。。
Private Sub Timer1_Timer()
call command5_click
end sub
我就是这样操作的。。。
Girl1983 2003-03-09
  • 打赏
  • 举报
回复
你数据库没关闭吧?

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧