You can use SetTimer API.To Create the Sample Project ----------------------------1. Start a new Standard EXE project in Visual Basic. Form1 is created by default.2. Add a TextBox and CommandButton to Form1.3. Add a module to the project by completing the following steps: a. From the Project menu, click Add Module. The Add Module dialog box appears. b. On the New tab, choose Module and click OK. A new module is added to your project.4. Copy the following code to the Code window of Module1: Option Explicit Declare Function SetTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long) As Long Global iCounter As Integer Sub TimerProc(ByVal hwnd As Long, _ ByVal uMsg As Long, _ ByVal idEvent As Long, _ ByVal dwTime As Long) iCounter = iCounter + 1 Form1.Text1.Text = CStr(iCounter) End Sub5. Copy the following code to the Code window of Form1: Option Explicit Dim lngTimerID As Long Dim BlnTimer As Boolean Private Sub Form_Load() BlnTimer = False Command1.Caption = "Start Timer" End Sub Private Sub Command1_Click() 'Starts and stops the timer. If BlnTimer = False Then lngTimerID = SetTimer(0, 0, 200, AddressOf TimerProc) If lngTimerID = 0 Then MsgBox "Timer not created. Ending Program" Exit Sub End If BlnTimer = True Command1.Caption = "Stop Timer" Else lngTimerID = KillTimer(0, lngTimerID) If lngTimerID = 0 Then MsgBox "couldn't kill the timer" End If BlnTimer = False Command1.Caption = "Start Timer" End If End Sub6. On the Run menu, click Start or press the F5 key to start the program. Click Start Timer to create a timer event. At each specified interval, the TextBox is updated with a new value. Click Stop Timer to stop the timer event.==========Since the parameter uElapse of SetTimer is UINT, it can meet your need.Best Regards,Parker Zhang.
paykun(小培) 的代码不错噢,试一下先。
How do you try it?Just wait for one or two hours?Good luck :)Parker Zhang.
Something to add,uElapse specifies the time-out value, in milliseconds. You can use a Long data type with a value of up to 2,147,483,647 milliseconds. Values beyond this limit result in a Run-time Error '6' Overflow. Parker Zhang.
'Module: Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)public sub Delay(byval nHour as Integer) 'nHour为小时 sleep nHour*3600*1000 end sub
Option Explicit Declare Function SetTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long) As Long Global iCounter As Integer Sub TimerProc(ByVal hwnd As Long, _ ByVal uMsg As Long, _ ByVal idEvent As Long, _ ByVal dwTime As Long) iCounter = iCounter + 1 Form1.Text1.Text = CStr(iCounter) End Sub5. Copy the following code to the Code window of Form1: Option Explicit Dim lngTimerID As Long Dim BlnTimer As Boolean Private Sub Form_Load() BlnTimer = False Command1.Caption = "Start Timer" End Sub Private Sub Command1_Click() 'Starts and stops the timer. If BlnTimer = False Then lngTimerID = SetTimer(0, 0, 200, AddressOf TimerProc) If lngTimerID = 0 Then MsgBox "Timer not created. Ending Program" Exit Sub End If BlnTimer = True Command1.Caption = "Stop Timer" Else lngTimerID = KillTimer(0, lngTimerID) If lngTimerID = 0 Then MsgBox "couldn't kill the timer" End If BlnTimer = False Command1.Caption = "Start Timer" End If End Sub 很好用。
谁要是有现成的源码就好啦。一定给分。
----------------------------1. Start a new Standard EXE project in Visual Basic. Form1 is created by default.2. Add a TextBox and CommandButton to Form1.3. Add a module to the project by completing the following steps: a. From the Project menu, click Add Module. The Add Module dialog box appears. b. On the New tab, choose Module and click OK. A new module is added to your project.4. Copy the following code to the Code window of Module1:
Option Explicit Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long Global iCounter As Integer Sub TimerProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long) iCounter = iCounter + 1
Form1.Text1.Text = CStr(iCounter)
End Sub5. Copy the following code to the Code window of Form1: Option Explicit
Dim lngTimerID As Long
Dim BlnTimer As Boolean Private Sub Form_Load()
BlnTimer = False
Command1.Caption = "Start Timer"
End Sub Private Sub Command1_Click()
'Starts and stops the timer. If BlnTimer = False Then
lngTimerID = SetTimer(0, 0, 200, AddressOf TimerProc)
If lngTimerID = 0 Then
MsgBox "Timer not created. Ending Program"
Exit Sub
End If
BlnTimer = True
Command1.Caption = "Stop Timer"
Else
lngTimerID = KillTimer(0, lngTimerID)
If lngTimerID = 0 Then
MsgBox "couldn't kill the timer"
End If
BlnTimer = False
Command1.Caption = "Start Timer"
End If End Sub6. On the Run menu, click Start or press the F5 key to start the program. Click Start Timer to create a timer event. At each specified interval, the TextBox is updated with a new value. Click Stop Timer to stop the timer event.==========Since the parameter uElapse of SetTimer is UINT, it can meet your need.Best Regards,Parker Zhang.
Parker Zhang.
Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)public sub Delay(byval nHour as Integer) 'nHour为小时
sleep nHour*3600*1000
end sub
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long Global iCounter As Integer Sub TimerProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long) iCounter = iCounter + 1
Form1.Text1.Text = CStr(iCounter)
End Sub5. Copy the following code to the Code window of Form1: Option Explicit
Dim lngTimerID As Long
Dim BlnTimer As Boolean Private Sub Form_Load()
BlnTimer = False
Command1.Caption = "Start Timer"
End Sub Private Sub Command1_Click()
'Starts and stops the timer. If BlnTimer = False Then
lngTimerID = SetTimer(0, 0, 200, AddressOf TimerProc)
If lngTimerID = 0 Then
MsgBox "Timer not created. Ending Program"
Exit Sub
End If
BlnTimer = True
Command1.Caption = "Stop Timer"
Else
lngTimerID = KillTimer(0, lngTimerID)
If lngTimerID = 0 Then
MsgBox "couldn't kill the timer"
End If
BlnTimer = False
Command1.Caption = "Start Timer"
End If End Sub
很好用。