Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_LSHIFT = &HA0
Sub main()
Dim ReturnValue, I
Dim sums As Integer
sums = 0
ReturnValue = Shell("notepad.exe", 1)
AppActivate ReturnValue
SendKeys "0", True
For I = 1 To 200
SendKeys "{+}" & I, True
sums = sums + I
Sleep 50
'DoEvents
If GetAsyncKeyState(VK_LSHIFT) Then Exit For
Next I
SendKeys "=" & sums, True
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_LSHIFT = &HA0
Sub main()
Dim ReturnValue, I
ReturnValue = Shell("notepad.exe", 1)
AppActivate ReturnValue
SendKeys "0", True
For I = 1 To 20
SendKeys "{+}" & I, True
Sleep 500
'DoEvents
If GetAsyncKeyState(VK_LSHIFT) Then Exit For
Next I
SendKeys "= ?", True
Private Sub Form_Load()
Set iTimer = Form2.Controls.Add("VB.Timer", "miTimer")
iTimer.Enabled = True
iTimer.Interval = 2000
End Sub
以上是Form1上的代码,在Form2上动态添加一个Timer控件miTimer,Form2不用Load