Yeah, I'm stuck maintaining some legacy software. Does anyone know of any good tutorials on creating classes and whatnot in VB6? My Google-fu seems to be failing me. :-/
VB6 classes are pretty basic. A good way to get a feel for the syntax is to fire up the class designer Add-on. Using that to design a simple dummy class will teach you pretty much everything you need to know.
Off the top of my head, properties are declared like this:
'Global variable inside the class
private m_Name as string
public property get Name() as string
Name = m_Name
end sub
public property let Name(sval as string)
m_name = sval
end sub
You can remove either the get or let to make a property read-only or write-only.
Then you can access the properties in this fashion
dim myClass as new ClassName
myClass.Name = "Mark"
debug.print myClass.Name
Methods can be Public or Private. I don't remember the syntax for declaring events off the top of my head.
Remember that you don't have constructors, so you need to use the Class_Initialize() method. I've just gone back to a VB6 position and found this one of the most irritating things (been spoiled by C# the last few years, but the rewrite will be fun!)
I can help your google searches. You should start your searches with -".net" and that should drastically reduce all the .Net results.
Here are some tutorials that I found:
If you're happy reading books, Francesco Balena's book "Programming Microsoft Visual Basic 6.0" is excellent for experienced programmers who already know what variables are, etc, and just want to learn VB. You should be able to pick it up secondhand fairly cheaply somewhere like AbeBooks
And remember that wen you using it you don't have inheritance, at least i've never found a way to do that, if you find it, please tell me, because i have the same problem that you do, maintaining old software.
for doing methods you declare as functions, using the modifier public or private
Also, in case you are writing .DLLs that are to be exposed to other applications, be aware of how VB6 manages your classes as COM objects. Basically, for instance if you create a class named MyClass, VB6 also generates an interface named (underscore)MyClass, which is then used as the default interface for MyClass coClass.
This only gets interesting when consuming your classes from, say, C++, otherwise you can forget it.
As well as classes, something that's not very well known is that you can use interfaces in VB6. This makes some simple OO styles possible.
Simply, you define your interface like this:
Public Sub Method1()
End Sub
Public Property Get Prop1() As Boolean
End Property
(i.e. with empty method and property stubs), then the classes that implement the interface like this:
Public Sub InterfaceName_Method1()
'implementation
End Sub
Public Property Get Prop1() As Boolean
'implementation
End Property
Each interface and implementation needs to be in a separate code file.
For more detail, this web page is a good reference.
Edit: As MarkJ commented, it is possible to spoof up inheritance using aggregation. He gave quite a nice article here.
The best reference I ever found for VB6 was by Dan Appleman. The second best was Hardcore Visual Basic by Bruce McKinney. The second one has the advantage that it's available online. Sounds like you're interested in Chapter 3: An Object Way of Basic.
Presumably you've read the manual? As well as reference material there are useful overviews. The "Programming with objects" chapter of the "Programmers Guide" covers classes.
Some parts of the overview documentation are aimed at beginners, but you can skim those bits.