Difficulties in understanding transfers

Why can a form have an open enumeration block if it cannot have a declaration of a public constant?

Also, if I have a public variable in the declaration section of a form, I can reference it throughout the application, but I MUST use dot notation, for example, form1.var1

However, if I put an enumeration block in a form declaration, I can refer to it in the rest of the application, but only if it is NOT a prefix with a dotted notation.

Is an enumeration blocking a single structure in a form that can or should only be specified externally without dot notation?

What is the logic of this that I am missing?

+4
source share
2 answers

The logic here is that an enumeration defines a type.

You already know about types because you use them everywhere. A class is a type. Thus, these are Integer , a Long , a String and all other built-in data types. And you can create custom user types using the Type keyword; eg.

 ' Defines a new type User Type User Name As String ID As Integer PhoneNumber As String End Type 

If you think about it, you will see that it makes sense. You never use an enumeration directly. Rather, you use it as a type. You declare variables that contain the value of this type of enumeration, just as you would declare a variable that contains a value of type Integer or String .

In contrast, a constant is not a type. This is just a regular value, but not otherwise than if you declared a regular variable, except that the value of the constant variable cannot be changed.

Types can be defined anywhere, inside or outside the class. However, variables must be defined inside the class or inside the module.

+4
source

The reason for this behavior is due to the fact that VB6 is the basis of COM. Most VB types are based on those available for a COM type library (found in all VB components and most common ActiveX components). VB Enum public statements are equivalent to the "Enum" found in the type library. However, Enums type libraries are top-level objects (other objects include Interface, CoClass, Module, Record, Union, and Alias). This means that VB refers to them as <ProjectName>. <Enum Name>, and this convention applies to the enumerated types created internally. The VB Object Browser is misleading when it says Form1.MyEnum - it just says where it is declared.

Regarding constants - unfortunately, this is a functional hole in VB6. COM type libraries support constants as part of the type library module, but this ability has never been added to VB6 (possibly because VB does not have a concept of a type library module).

+3
source

All Articles