- 关 键 词:
- visual basic
- opera
- word
- nat
Instead of using Visual Basic注释:s DoEvents, try doing events
In many situations, the DoEvents keyword can be a real boon. As you may
know, this keyword yields operation to the operating system so that it
can process other events. Many times after initiating a procedure, you
may want to pause execution to gather further information from an end
user via a form. For example, consider a project with two forms. The
main form performs a calculation and displays the results. The second
form lets an end user manually enter two numbers for the calculation.
When you click the second form注释:s Submit button, the main form multiplies
the user-entered numbers and displays the results.
Typically, to handle this feature, you might use DoEvents to wait until
the user has entered the two numbers. For instance, you might set up a
looping procedure like so:
Private Sub Command1_Click()
Dim Myform as frmEntry
Set Myform = New frmEntry
With Myform
.Show
Do
DoEvents
Loop Until Myform.Ready
注释:Do some calculations based on the entry
txtResults = .txtNum1 * .txtNum2
End With
Unload frm
Set frm = Nothing
End Sub
This code assumes that you注释:ve also declared a public variable named
Ready in the entry form, and that the entry form sets it equal to True
when the user completes the entry process. Unfortunately, the DoEvents
keyword comes with a price, especially when you place it inside a loop.
It consumes a lot of system resources.
As a better alternative, consider creating a custom event that the entry
form triggers when the user finishes entering data, like so:
Public Event NumbersSubmitted()
Public NumOne As Long
Public NumTwo As Long
Private Sub cmdSubmit_Click()
NumOne = CLng(txtNum1)
NumTwo = CLng(txtNum2)
Unload Me
RaiseEvent NumbersSubmitted
End Sub
Then, you can add code that reacts to this event in the original form, as in:
Private Sub frmNumEntry_NumbersSubmitted()
With frmNumEntry
txtResults = .NumOne * .NumTwo
Set frmNumEntry = Nothing
End With
End Sub
Here, frmNumEntry is a variable with form-level scope and declared
WithEvents in the main form注释:s general declaration section, like this:
Dim WithEvents frmNumEntry As frmNumberEntry专题:http://www.qqread.com/vb/u277288.html进入讨论组讨论。
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- VB+Access设计图书管理系统 (104238次浏览)
- VB设计有语音报时和报警功能的闹钟 (13528次浏览)
- 用VB打造“超酷”个性化菜单 (667次浏览)
- VB基础学习:编码规范 (654次浏览)
- 对注册表进行编程的“捷径” (646次浏览)
- 在IIS中建立WEB站点的例子! (603次浏览)
- 用VB6.0设计简易赛车游戏 (414次浏览)
- VB6 和 VB2005 中的用户界面控件 (339次浏览)
- 导入注册表设置 (308次浏览)
- 用Visual Basic.NET编写扑克牌游戏 (189次浏览)



