未找到用户定义类型,这怎么改?

来源:百度知道 编辑:UC知道 时间:2024/06/18 05:10:26
程序源码含以下部分:

标准模块(mTimer):
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Public TimerColl As New VBA.Collection

Public Sub TimeProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
Dim Timer As Timer, lpTimer As Long
lpTimer = TimerColl("ID:" & idEvent)
CopyMemory Timer, lpTimer, 4&
Timer.PulseTimer
CopyMemory Timer, 0&, 4&
End Sub

类模块(Timer):
Option Explicit

Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long

Private m_TimerID As Long
Private m_Interval As Long
Private m_Enabled

这个代码你复制好了以后,把模块的名称改为“mTimer”,类模块的名字改为“timer”,然后,窗体中的代码修改成这样:
Private WithEvents Timer1 As timer
Private Sub Form_Load()
Set Timer1 = New timer '这里改一下
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Debug.Print Now
End Sub
注意打开你的立即窗口,运行程序,就能看到效果了。我这里测试成功。