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

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

问题描述

在 VB6/VBA 中,您可以在特定的 SubFunction 方法之外声明模块级变量.我在模块内部使用过 PrivatePublic 并像这样理解它们:

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 - 对模块内的所有代码和模块外的所有代码可见,本质上使其成为全局的.
  • Private - 仅对模块内的代码可见.
  • 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.

我注意到您可以使用 DimGlobal 作为模块化变量的修饰符.当用作模块化字段的访问修饰符时,DimGlobal 是否分别不同于 PrivatePublic?如果有,它们有何不同?

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?

推荐答案

DimPrivate 的工作方式相同,但常见的约定是使用 Private 在模块级别,Dim 在子/功能级别.PublicGlobal 在功能上几乎相同,但是 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天全站免登陆