Dim,Global,Public和Private作为模块化现场访问修饰符有什么区别? [英] What is the difference between Dim, Global, Public, and Private as Modular Field Access Modifiers?

查看:120
本文介绍了Dim,Global,Public和Private作为模块化现场访问修饰符有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB6 / VBA中,您可以在特定的 Sub Function 方法之外声明模块级变量。在模块内部之前,我曾使用 Private Public 并像这样理解它们:

In VB6/VBA, you can declare module-level variables outside of a specific Sub or Function method. I've used Private and Public before inside modules and understand them like so:


  • 公共-模块内部的所有代码和模块外部的所有代码均可见,从而使它成为全局的。

  • 私有-仅对模块内部的代码可见。

  • Public - visible to all code inside the module and all code outside the module, essentially making it global.
  • Private - visible only to code inside the module.

我注意到您可以使用 Dim Global 作为模块变量的修饰符。 Dim Global 是否不同于 Private 公共分别用作模块化字段上的访问修饰符?如果是这样,它们有何不同?

I've noticed that you can use Dim and Global as modifiers for modular variables. Are Dim and Global different from Private and Public, respectively, when used as access modifiers on modular fields? If so, how are they different?

推荐答案

Dim Private 的工作原理相同,尽管通用约定是在模块级别使用 Private Dim 在子/功能级别。 公共 Global 在功能上几乎相同,但是 Global 只能在标准模块中使用,而 Public 可以在所有上下文(模块,类,控件,窗体等)中使用。 Global 来自旧版本的VB,可能为了向后兼容而保留,但已被 Public 完全取代。

Dim and Private work the same, though the common convention is to use Private at the module level, and Dim at the Sub/Function level. Public and Global are nearly identical in their function, however Global can only be used in standard modules, whereas Public can be used in all contexts (modules, classes, controls, forms etc.) Global comes from older versions of VB and was likely kept for backwards compatibility, but has been wholly superseded by Public.

这篇关于Dim,Global,Public和Private作为模块化现场访问修饰符有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆