请各位帮忙看一下一个VB小程序的问题.(关于正确显示软件运行时间的)

littlesun88 2003-01-02 03:42:20
Option Explicit
Dim t As String
Dim errors As Integer
Dim rights As Integer
Dim rate As Integer
Dim s As Double
Dim e As Double


Private Sub Command1_Click()
Randomize Timer
Dim i As Integer
Dim s As String
For i = 0 To 15

s = s & Chr(Int(Rnd * 26) + 97)
Next i
Label2.Caption = s
t = ""
Text1.Text = ""
errors = 0
rights = 0
s = Timer

End Sub

Private Sub Command2_Click()
e = Timer
Label3.Caption = "正确:" & rights
Label4.Caption = "错误:" & errors
Label5.Caption = "耗时:" & Int(e - s) + 1 ---这里是统计时间的变量

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
t = t & Chr(KeyAscii)
Text1.Text = t
If Len(t) > Len(Label2.Caption) Then
Exit Sub
End If
If KeyAscii <> Asc(Mid(Label2.Caption, Len(t), 1)) Then
errors = errors + 1
'Debug.Print errors, Chr(KeyAscii), Mid(Label2.Caption, Len(t), 1)
Else
rights = rights + 1
End If

End Sub


把这个存为*.frm文件来调试.
我这个程序显示的时间不是我们现在用的"秒",怎么改才能让他表示秒呢?
...全文
60 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
littlesun88 2003-01-04
  • 打赏
  • 举报
回复
收到,谢谢~
zyl910 2003-01-02
  • 打赏
  • 举报
回复
VB对同名变量的处理:

If 过程中Dim(或Static)定义了 Then
用过程中的变量
ElseIf 自身模块Private定义了 Then
用自身模块Private的变量
ElseIf 标准模块中的Public定义了 Then
用标准模块Public的变量
ElseIf 在标准模块中有同名的Public变量 Then
必须 模块名.变量名,否则不能通过编译
End If
zyl910 2003-01-02
  • 打赏
  • 举报
回复
函数执行结束后变量才会释放
chenyu5188 2003-01-02
  • 打赏
  • 举报
回复
UP了
littlesun88 2003-01-02
  • 打赏
  • 举报
回复
哦,是有2个S啊,不过我是在第一个S使用完后才重新定义S的值的,这个为什么就不可以呢?
zyl910 2003-01-02
  • 打赏
  • 举报
回复
你没有注意吗
有两个s


Dim s As Double


Private Sub Command1_Click()
Randomize Timer
Dim i As Integer
Dim s As String
littlesun88 2003-01-02
  • 打赏
  • 举报
回复
谢谢,调试成功了,您能告诉我为什么用一个变量就不可以吗???
zyl910 2003-01-02
  • 打赏
  • 举报
回复
用另一个变量储存时间

Option Explicit
Dim t As String
Dim errors As Integer
Dim rights As Integer
Dim rate As Integer
Dim ts As Double
Dim e As Double


Private Sub Command1_Click()
Randomize Timer

Dim i As Integer
Dim s As String
For i = 0 To 15
s = s & Chr(Int(Rnd * 26) + 97)
Next i
Label2.Caption = s
t = ""
Text1.Text = ""
errors = 0
rights = 0
ts = Timer

End Sub

Private Sub Command2_Click()
e = Timer

Label3.Caption = "正确:" & rights
Label4.Caption = "错误:" & errors
Label5.Caption = "耗时:" & Int(e - ts) + 1 ---这里是统计时间的变量

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
t = t & Chr(KeyAscii)
Text1.Text = t
If Len(t) > Len(Label2.Caption) Then
Exit Sub
End If
If KeyAscii <> Asc(Mid(Label2.Caption, Len(t), 1)) Then
errors = errors + 1
'Debug.Print errors, Chr(KeyAscii), Mid(Label2.Caption, Len(t), 1)
Else
rights = rights + 1
End If

End Sub
littlesun88 2003-01-02
  • 打赏
  • 举报
回复
您能说得具体点吗?该怎么解决呢?
softlead 2003-01-02
  • 打赏
  • 举报
回复
timer计算时间是不准确的,在打开photoshop 等大软时你的tiemr计时就不准确了,可以想办法记住开始的系统时间,用最后的时间减去开始时的时间就可以知道准确的运行时间!
littlesun88 2003-01-02
  • 打赏
  • 举报
回复
也许我上面的问题提得不好,我再重新说明一下:
我的思想是在运用一个Timer来计算时间,在结束程序的时候能显示程序所运行的时间.
当程序开始运行时启动Timer,在点了"结束"按钮后将Timer的值给变量S,可是这个值不是一秒为单位的,我要做什么函数处理才能将S输出为秒呢?
littlesun88 2003-01-02
  • 打赏
  • 举报
回复
我这里的S只是让他来做统计时间的变量,只要最后能显示出来所用的时间(以秒为单位)就可以了.
littlesun88 2003-01-02
  • 打赏
  • 举报
回复
zyl910(910:分儿,我来了!) ,
这个是什么意思?让我去掉些代码??
Private Sub Command1_Click()
Randomize Timer
Dim i As Integer
Dim s As String
!!!!!!!!!!!
of123 2003-01-02
  • 打赏
  • 举报
回复
去掉 Dim s As String
XLYT 2003-01-02
  • 打赏
  • 举报
回复
你的s究竟是想让它做字符还是做数字?
zyl910 2003-01-02
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Randomize Timer
Dim i As Integer
Dim s As String
!!!!!!!!!!!

7,785

社区成员

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

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