drizzt
drizzt

Reputation: 2886

Visual Basic 6 public variables to properties

i`m working on the legacy project in VB6 with huge object all with public variables. I want to convert these public variables to private variable/property combinations. Is there some tools with which i can do these conversion?(optimally all variables in class at once)

Thanks

Upvotes: 2

Views: 1186

Answers (3)

C-Pound Guru
C-Pound Guru

Reputation: 16368

MZ-Tools is a free add-in that has a feature that allows converting a public variable to a property.

Upvotes: 3

Konrad Rudolph
Konrad Rudolph

Reputation: 545686

Don’t do the conversion, it’s not needed. The VB compiler does this automatically for all exposed classes (i.e. all classes that are exported in COM DLLs) and it’s not required for all other fields since these are used internally only and there’s no difference between a field and a property for the user.

VB6 is the only language to do this right, in not allowing public fields at all, and implicitly converting them.

To recap: there’s nothing wrong with public variables in VB6 since the usual disadvantages of public variables don’t apply to them. In particular, they don’t break encapsulation.

Upvotes: 5

Vinay Sajip
Vinay Sajip

Reputation: 99385

I don't know of any refactoring tool for VB6, but I'd approach the problem by writing a script to scan the source file, search for lines matching "Public Dim ..." and replacing those lines with the appropriate "Private Dim ..." and property accessors.

Upvotes: 1

Related Questions