4
votes

I'm working on an old vb6 application (long story, .NET Framework is not available).

I want to know, can I declare a vb6 Class Property item as an Enum?

e.g.

Public Enum WinInetPort
    INTERNET_INVALID_PORT_NUMBER = 0
    INTERNET_DEFAULT_FTP_PORT = 21
    INTERNET_DEFAULT_GOPHER_PORT = 70
    INTERNET_DEFAULT_HTTP_PORT = 80
    INTERNET_DEFAULT_HTTPS_PORT = 443
    INTERNET_DEFAULT_SOCKS_PORT = 1080
End Enum

Class Module:

Private m_Port As WinInetPort
Public Property Get Port() As WinInetPort
    Port = m_Port
End Property
Public Property Let Port(val As WinInetPort)
    m_Port = val
End Property

But, I get errors when compiling

Only comments may appear after End Sub, End Function, or End Property

The error is highlighted on the next Private statement in the class.

I've read somewhere on the net vb6 classes can't expose Public Constants - is there a workaround?

Thanks

1
The error you get is not related to the fact that the use of Enums has some limitataions in VB6. You simply made a typo somewhere.Dabblernl
What you have is perfectly fine & woks for me with either the enum declared in the class or a module, the problem must lie elsewhere.Alex K.
Try adding another Property after Port, then run the code. If I have nothing after the Port Property in the class, then it will work, if I have some other property defined after the Port property, I get the error.Ben
Far out vb6 is naff. If I move all of my Private declares above the Property, I don't seem to get the error. But because I've been mostly coding in vb.NET and C#.NET I've gotten used to declaring the Private variable just above the property. Seems VB6 doesn't like this.Ben
Yep, the top of the module/class in VB6/A is the place where declarations have to go.Alex K.

1 Answers

5
votes

Make sure all of your Private statements are placed above the Property declarations.