Dim vs Private/Public

前端 未结 2 812
甜味超标
甜味超标 2021-01-05 16:20

At the head of a module, I wish to declare some global variables for use in various subs/functions.

What is the difference between

Dim x as string

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 17:15

    Private and public control the scope of the variable or object you're declaring.

    Private will only allow members of the relative module/class/whatever to access the instance

    public will allow anything in the same scope as the module/class/whatever to access it.

    Dim defaults to either public or private, depending on what you're working in. A class for example, will default to private. I suggest reading up on encapsulation and OOP to get a better feel for this.

提交回复
热议问题