求一个VB秒表的源代码,精确至0.01秒
3个回答
展开全部
1)
启动visual basic6.0 ,打开一个新的标准工程。
2)
在窗体上Form1上添加6个标签空间(Label) 2个命令按钮(CommandButton)和1个计时器(Timer)。命令按钮的Caption属性分别为“启动”“停止”
Timer1的Interval属性为10
Label1 Label2 Label3的Caption属性分别为“开始时间”“结束时间”“经过时间” Timer1的Enable属性为False
3)代码
Dim Starttime As Variant
Dim End time As Variant
Dim Elapsed As Variant
Private Sub cmdStart_Click()
'显示开始时间
lblStart.Caption=Time$
Starttime=Now
'启动时钟控件
Timer1.Enabled=Ture
End Sub
Private Sub cmdStop_Click()
'记录停止时间
Endtime=Now
'关闭时钟控件
Timer1.Enabled=False
'显示经过时间
lblApaed.Caption=Format(Endtime-Starttime,"hh:mm:ss"
End Sub
Private Sub Timer1_Timer()
lblStop.Caption=Time$
End Sub
以上是用VB6.0实现的
启动visual basic6.0 ,打开一个新的标准工程。
2)
在窗体上Form1上添加6个标签空间(Label) 2个命令按钮(CommandButton)和1个计时器(Timer)。命令按钮的Caption属性分别为“启动”“停止”
Timer1的Interval属性为10
Label1 Label2 Label3的Caption属性分别为“开始时间”“结束时间”“经过时间” Timer1的Enable属性为False
3)代码
Dim Starttime As Variant
Dim End time As Variant
Dim Elapsed As Variant
Private Sub cmdStart_Click()
'显示开始时间
lblStart.Caption=Time$
Starttime=Now
'启动时钟控件
Timer1.Enabled=Ture
End Sub
Private Sub cmdStop_Click()
'记录停止时间
Endtime=Now
'关闭时钟控件
Timer1.Enabled=False
'显示经过时间
lblApaed.Caption=Format(Endtime-Starttime,"hh:mm:ss"
End Sub
Private Sub Timer1_Timer()
lblStop.Caption=Time$
End Sub
以上是用VB6.0实现的
参考资料: http://zhidao.baidu.com/question/17660193.html?fr=qrl3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不用API就只能用Timer了,Timer可以作出你说的秒表,但无法精确到0.01秒,Timer的精确度约1/18秒,大约是0.056秒,你可以用百度搜索下
VB记时
,
如果要到0.01秒级,不用API,没办法
VB记时
,
如果要到0.01秒级,不用API,没办法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
精确到毫秒
代码如下
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CStopWatch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'
' Win32 API declarations.
'
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function timeGetDevCaps Lib "winmm.dll" (lpTimeCaps As TIMECAPS, ByVal uSize As Long) As Long
'
' API Structure definitions.
'
Private Type TIMECAPS
wPeriodMin As Long
wPeriodMax As Long
End Type
'
' Set aside storage for private member variables.
'
Private m_StartTime As Long
Private m_PeriodMin As Long
Private m_PeriodMax As Long
' ********************************************
' Initialize
' ********************************************
Private Sub Class_Initialize()
'
' Retrieve system timer resolution.
'
Dim tc As TIMECAPS
Call timeGetDevCaps(tc, Len(tc))
m_PeriodMin = tc.wPeriodMin
m_PeriodMax = tc.wPeriodMax
'
' Initialize starting time.
'
m_StartTime = timeGetTime()
End Sub
' ********************************************
' Public Properties
' ********************************************
Public Property Get Elapsed() As Long
'
' Read-Only: return elapsed time in milliseconds
' since stopwatch was reset.
'
Elapsed = timeGetTime() - m_StartTime
End Property
Public Property Get MinimumResolution() As Long
'
' Read-Only: return minimum number of milliseconds
' timer is capable of resolving.
'
MinimumResolution = m_PeriodMin
End Property
Public Property Get MaximumResolution() As Long
'
' Read-Only: return maximum number of milliseconds
' timer is capable of resolving.
'
MaximumResolution = m_PeriodMax
End Property
' ********************************************
' Public Methods
' ********************************************
Public Sub Reset()
'
' Reinitialize starting time.
'
m_StartTime = timeGetTime()
End Sub
代码如下
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CStopWatch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'
' Win32 API declarations.
'
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function timeGetDevCaps Lib "winmm.dll" (lpTimeCaps As TIMECAPS, ByVal uSize As Long) As Long
'
' API Structure definitions.
'
Private Type TIMECAPS
wPeriodMin As Long
wPeriodMax As Long
End Type
'
' Set aside storage for private member variables.
'
Private m_StartTime As Long
Private m_PeriodMin As Long
Private m_PeriodMax As Long
' ********************************************
' Initialize
' ********************************************
Private Sub Class_Initialize()
'
' Retrieve system timer resolution.
'
Dim tc As TIMECAPS
Call timeGetDevCaps(tc, Len(tc))
m_PeriodMin = tc.wPeriodMin
m_PeriodMax = tc.wPeriodMax
'
' Initialize starting time.
'
m_StartTime = timeGetTime()
End Sub
' ********************************************
' Public Properties
' ********************************************
Public Property Get Elapsed() As Long
'
' Read-Only: return elapsed time in milliseconds
' since stopwatch was reset.
'
Elapsed = timeGetTime() - m_StartTime
End Property
Public Property Get MinimumResolution() As Long
'
' Read-Only: return minimum number of milliseconds
' timer is capable of resolving.
'
MinimumResolution = m_PeriodMin
End Property
Public Property Get MaximumResolution() As Long
'
' Read-Only: return maximum number of milliseconds
' timer is capable of resolving.
'
MaximumResolution = m_PeriodMax
End Property
' ********************************************
' Public Methods
' ********************************************
Public Sub Reset()
'
' Reinitialize starting time.
'
m_StartTime = timeGetTime()
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询