频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

试代用VB中DoEvents事件.

来源: 作者: 出处:巧巧读书 2006-11-12 进入讨论组

  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进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
最新论坛文章
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章