主题:请帮我看看哪里错了
ictest
[专家分:0] 发布于 2011-02-20 04:38:00
机时统计是我编写的一个小软件,其原理是:在文本框输入1~4中的任一个数字,按开始键,则label7开始计时,同时读取C盘下的j750-user.txt文件,看是1~4中哪个数字,相应的在label6中显示部门。当按停止键时,则停止计时,清空label6,label7,并在C盘下的j750-机时统计.txt文件中记录使用者和时间。
经过试运行,发现几个问题:1,软件一运行则开始往C盘下的j750-机时统计.txt文件中记录使用者和时间;2,按停止键label6不清空;3,按了停止键还在往C盘下的j750-机时统计.txt文件中记录使用者和时间。
请问,是哪里错了呢?应该怎么修改?谢谢!最好能在原程序上修改后再挂上来,谢谢前辈们了!!
最后更新于:2011-02-20 04:44:00
回复列表 (共4个回复)
沙发
老大徒伤悲 [专家分:29120] 发布于 2011-02-20 11:07:00
说实话,我很欣赏你的提问方式。所以尽管我对这个问题不感兴趣,但还是给你看上一看。
板凳
老大徒伤悲 [专家分:29120] 发布于 2011-02-20 11:10:00
很遗憾,你没附上你的
j750-user.txt
文件,不好测试。只能拿人脑当电脑用了。
3 楼
老大徒伤悲 [专家分:29120] 发布于 2011-02-20 11:43:00
once这个变量是做什么的?
4 楼
老大徒伤悲 [专家分:29120] 发布于 2011-02-20 11:56:00
因为不清楚你程序的意图,也联系不上你,先只按照你上面说的三个问题修改,其他虽然明显的问题,我先不改动,都保留你的原样。
可以肯定:
1、修改后,满足你上述三项要求;
2、修改后,不能达到你没有说出来的要求,可能还有你原来能完成,现在不能了。
Private i1 As Long
Private b1 As Long
Private Sub Form_Load()
Form1.Move (Screen.Width - Form1.Width) / 2, (Screen.Height - Form1.Height) / 2 '窗口居中
once = False
Timer1.Enabled = False '所有计时器暂不工作,等待开始命令
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer2.Interval = 1000
Timer3.Interval = 1000
Timer4.Interval = 1000
Label6.Caption = ""
End Sub
Private Sub Timer1_Timer()
Label7.Caption = Time
Label10.Caption = Time
Label13.Caption = Time
End Sub
Private Sub Timer2_Timer()
On Error Resume Next
Dim x1 As Integer
Dim s1 As String
Dim y1 As String
Open "C:\j750-state.txt" For Binary As #1
Do Until EOF(1)
Line Input #1, s1
Loop
Close #1
If s1 = "1" Then
Shape1.BackStyle = 1
Shape1.BackColor = QBColor(10) '绿色
Label7.ForeColor = vbGreen
Timer1.Enabled = True
If Timer1.Enabled = True Then i1 = i1 + 1
x1 = Val(i1)
Label7.Caption = Format(x1 / 86400, "hh:mm:ss")
'Label7.Caption = (x1 \ 3600) & ":" & ((x1 Mod 3600) \ 60) & ":" & (x1 Mod 60)
'Label3.Caption = (X \ 3600) & ":" & ((X Mod 3600) \ 60) & ":"
Else
once = False
Timer1.Enabled = False
Open "c:\j750-机时统计.txt" For Append As #1
Print #1, "----------junpinbu----------"
Print #1, Date & " | " & " J750 由 " & Label6.Caption; "运行了:" & " "; Label7.Caption
Close #1
i1 = 0
Label6.Caption = ""
Label7.Caption = ""
Shape1.BackStyle = 0
' Shape1.BackStyle = 1
' Shape1.BackColor = QBColor(12) '红色
' Label7.ForeColor = vbRed
' Timer1.Enabled = True
' If Timer1.Enabled = True Then b1 = b1 + 1
' x1 = Val(b1)
' Label7.Caption = Format(x1 / 86400, "hh:mm:ss")
'Label7.Caption = (x1 \ 3600) & ":" & ((x1 Mod 3600) \ 60) & ":" & (x1 Mod 60)
'Label2.Caption = (X \ 3600) & ":" & ((X Mod 3600) \ 60) & ":"
End If
Open "C:\j750-user.txt" For Binary As #1
Do Until EOF(1)
Line Input #1, y1
Loop
Close #1
If y1 = "1" Then
Label6.ForeColor = vbGreen
Label6.Caption = "一部"
End If
If y1 = "2" Then
Label6.ForeColor = vbGreen
Label6.Caption = "二部"
End If
If y1 = "3" Then
Label6.ForeColor = vbGreen
Label6.Caption = "六部"
End If
If y1 = "4" Then
Label6.ForeColor = vbGreen
Label6.Caption = "八部"
End If
End Sub
Private Sub Command1_Click()
Open "C:\j750-state.txt" For Append As #1
Print #1, "1"
Close #1
Open "C:\j750-user.txt" For Append As #1
Print #1, Text1.Text
Close #1
End Sub
Private Sub Command2_Click()
Open "C:\j750-state.txt" For Append As #1
Print #1, "0"
Close #1
Timer1.Enabled = False '因为你一切工作都在计时器事件里,所以停止应该让计时器停止工作。
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
'要清空标签必须有指令!
Label6 = ""
End Sub
我来回复