'在 Form_Load 中加入 Call MyLog("启动")
'在 Form_Unload 中加入 Call MyLog("野睁退出")
Private Sub Form_Load()
Call MyLog("启动颂拦岁")
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call MyLog("退出")
End Sub
Private Sub MyLog(nStr As String)
Dim F As String, H As Long
nStr = Format(Now, "yyyy-mm-dd hh:mm:ss") &nStr
F = "C:\myprog.log"
'如果要将文件保存到与你的 exe 相同的文件夹,将上句改为 F = App.Path &"\myprog.log"衡仿
H = FreeFile
Open F For Append As #H
Print #H, nStr
Close #H
End Sub
Const m As Integer = 10
Private Sub Command1_Click()
Open "d:\1.txt" For Append As #1
Dim a(1 To m) As Integer
Dim i As Integer, n As Integer
For i = 1 To m
n = Val(InputBox("请输入分数(0~100):", "输入框", "60"))
If n >= 0 And n <= 100 Then
a(i) = n
Else
i = i - 1
Print #1, Now & "报错" & n
End 兆含If
Next
Close #1
End Sub
注意,语句Open "d:\1.txt" For Append As #1 就是以追加方式记录,会保留任何时候的错误。希望能对你有帮助,见族改笑下图,是多次歼码启动保留的结果:
可以直接按文本文件顺序读取。比对每一行的时间尺薯(前8个字符),如果跟当前时握银间符合,则把后面的信息输出。不过你这个题目段困宴有问题,时间信息你是以秒计算的,万一时间不一致怎么办。Dim TempString As String '临时字符串
Dim TempStr1 As String, TempStr2 As String '输出内容信息变量
Open App.Path + "\1.Log" For Input As #1
Do Until EOF(1)
Line Input #1, TempString
If Format(Time$, "hh:mm:ss") = Left(TempString, 8) Then
TempOutputStr = Mid(TempString, 9)
Exit Do
End If
Loop
Close #1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)