VB操作Excel无法更新的问题研究(续)

本文探讨了在编程中窗体隐藏与卸载的不同之处。隐藏窗体使其不可见但保留内存中的状态,而卸载窗体会从内存中完全移除,无法再访问其属性和方法。此外还介绍了如何通过代码实现这两种操作,并强调了卸载所有窗体对于资源管理和避免内存泄漏的重要性。

初步找到问题所在,是因为使用了form.hide而不是unload form。也就是隐藏窗体还是关闭窗体,导致了数据更新问题。

You can hide a form so that it is not visible to a user. When the form is hidden, the user cannot interact with the form, but you still have full programmatic control of them.

To hide a form

Use the Hide method.
For example, in the code associated with the Click event of a command button, you could include the following line of code:

THISFORM.Hide

When the user clicks the command button, the form remains in memory, but is not visible.

Releasing a Form
You can allow a user to release a form when he or she is finished interacting with it. When you release a form, you can no longer access properties and methods of the form.

To release a form

Call the Release method.
For example, in the code associated with the Click event of a command button, you could include the following line of code:

THISFORM.Release

When the user clicks the command button, the form closes.

Unload Forms

This will unload all forms in memory before the calling form is unloaded. Not only does this unload each form, it also fires each form's unload event, allowing for a more thorough clean up. Since this is placed in the Query_Unload event, errors can be handled and decisions can be made if the unloading should continue. This is especially useful when using other third-party controls such as the splitter control.

Place the following code in your main form's Query_Unload event.


Dim f As Form

For Each f In Forms
If f.hwnd <> Me.hwnd Then
Unload f
End If
Next

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值