不对啊!是不是电脑报出错了??

Smallfrogs 2001-07-20 11:28:49
昨天翻阅《电脑报》发现在去年的电脑报上有一个小程序很有趣,它可以记录开机、关机时间。它使用VB,但是我把报纸上的文章输入到电脑里面的时候发现无法编译成为EXE文件,请大家帮我看看源程序有哪里错了?不然为什么无法编译成EXE文件?

源程序如下:(本例无需窗体)

Dim begintime
Private Sub Form_Load()
Me.Hide
begintime = Now
End Sub
Private Sub Form_UnLoad(Cancel As Integer)
endtime = Now
n = DateDiff("N", begintime, endtime)
Dim fso As New FileSystemObject
Dim txtfile As TextStream
Set a = App
If fso.FileExists(a.Path & "\开机纪录.txt") Then
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForAppending)
Else
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForWriting, True)
End If
txtfile.Write "开机时间" & begintime
txtfile.Write " " & "关机时间" & endtime
txtfile.Write " " & "时间长度" & n & "分钟"
txtfile.WriteBlankLines 2
End Sub

Dim begintime
Private Sub Form_Load()
Me.Hide
begintime = Now
End Sub
Private Sub Form_UnLoad(Cancel As Integer)
endtime = Now
n = DateDiff("N", begintime, endtime)
Dim fso As New FileSystemObject
Dim txtfile As TextStream
Set a = App
If fso.FileExists(a.Path & "\开机纪录.txt") Then
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForAppending)
Else
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForWriting, True)
End If
txtfile.Write "开机时间" & begintime
txtfile.Write " " & "关机时间" & endtime
txtfile.Write " " & "时间长度" & n & "分钟"
txtfile.WriteBlankLines 2
End Sub

Dim begintime
Private Sub Form_Load()
Me.Hide
begintime = Now
End Sub
Private Sub Form_UnLoad(Cancel As Integer)
endtime = Now
n = DateDiff("N", begintime, endtime)
Dim fso As New FileSystemObject
Dim txtfile As TextStream
Set a = App
If fso.FileExists(a.Path & "\开机纪录.txt") Then
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForAppending)
Else
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForWriting, True)
End If
txtfile.Write "开机时间" & begintime
txtfile.Write " " & "关机时间" & endtime
txtfile.Write " " & "时间长度" & n & "分钟"
txtfile.WriteBlankLines 2
End Sub
...全文
114 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qaymuic 2001-07-22
  • 打赏
  • 举报
回复
最简单的方法,建立一个窗体:
在窗体的load事件和unload事件中插入以上代码。(这是你出现无法编译错误的原因)
引用Microsoft Scripting Runtime(这样,才能保证你的程序正常运行)
qaymuic 2001-07-22
  • 打赏
  • 举报
回复
这个例子是有窗体的。你必须把窗体定义的那部分代码复制过来。再存为.frm文件。
如果原文没有这部分代码,你必须手工创建一个窗体,再将代码复制过来。(尽管此窗体没有任何其他控件,只有load和unload事件)
xxlroad 2001-07-22
  • 打赏
  • 举报
回复

请按 Ctrl+T

然后 按楼上说的去做
Smallfrogs 2001-07-21
  • 打赏
  • 举报
回复
谢谢大家.人人有分!
MonkeyLin 2001-07-21
  • 打赏
  • 举报
回复
单击“工程”菜单,选“部件”,在列表里找Microsoft Script Runtime,在其前面打勾……
好好努力把……
TechnoFantasy 2001-07-21
  • 打赏
  • 举报
回复
点菜单 Project | References ,再窗口列表中选择 Microsoft Scripting Runtime ,然后
确定。
Smallfrogs 2001-07-21
  • 打赏
  • 举报
回复
如何引用fso的库?我还是初学者。
Leemaasn 2001-07-21
  • 打赏
  • 举报
回复
工程-引用-microsoft script runtime
pp616 2001-07-20
  • 打赏
  • 举报
回复
Dim begintime
Private Sub Form_Load()
Me.Hide
begintime = Now
End Sub
Private Sub Form_UnLoad(Cancel As Integer)
endtime = Now
n = DateDiff("N", begintime, endtime)
Dim fso As New FileSystemObject
Dim txtfile As TextStream
Set a = App
If fso.FileExists(a.Path & "\开机纪录.txt") Then
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForAppending)
Else
Set txtfile = fso.OpenTextFile(a.Path & "\开机纪录.txt", ForWriting, True)
End If
txtfile.Write "开机时间" & begintime
txtfile.Write " " & "关机时间" & endtime
txtfile.Write " " & "时间长度" & n & "分钟"
txtfile.WriteBlankLines 2
End Sub

先引用fso的库!!!!

7,763

社区成员

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

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