• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How do I create a class in VB6?

Chaotic42

Lifer
Forgive me, I'm not a programmer and I can't find this anywhere.

Let's say I'd like to create a new class "Dog" (I assume class is the right word, it's not a method). I'd like to define Dog as having the following properties:

-
Color as integer
Breed as string
Weight as double
Barks as boolean
-

For some reason I can't figure out how to do this. Maybe I suck at Google, I don't know. Can anyone paste me some code really quickly?
 
I think VB Calls them "types" or "data types" and not classes, but I could be wrong. You are right that they are called classes in OOP, but VB6 is not really an OOL.
 
Thanks. That helped out. Apparently you have to put these in the "standard module". Then use the "Type" command (Minus the dashes):

Option Explicit
Public Type Dog
---Color as integer
---Breed as string
---Weight as double
---Barks as boolean
End Type

Then you can use the type normally after declaring it in the "regular" part of the program:

dim Fido as Dog
Fido.Barks = False
Fido.Weight=35.4
.
.
.

The whole "standard module" thing seems kind of weird to me. I'd like to just be able to do it in each subroutine. Oh, well. Thanks again Thyme. :beer:
 
It's been over 5 years since I did anything with VB6, and I didn't use it extensively then, but I do believe it supported actual classes with methods and whatnot. What you have there is closer to a struct, and if that's all you need that's fine. But to create a class, I believe it was similar to creating a new module, you just select class instead of module.

Actually most of my VB experience was porting a VB6 app to Embedded Visual Basic, and iirc one of the obstacles I had to overcome was that EVB did not support classes and VB6 did.
 
Originally posted by: mugs
It's been over 5 years since I did anything with VB6, and I didn't use it extensively then, but I do believe it supported actual classes with methods and whatnot. What you have there is closer to a struct, and if that's all you need that's fine. But to create a class, I believe it was similar to creating a new module, you just select class instead of module.

Actually most of my VB experience was porting a VB6 app to Embedded Visual Basic, and iirc one of the obstacles I had to overcome was that EVB did not support classes and VB6 did.

Yeah, I think it does support true classes, I use lots of what I think are classes all of the time (can you tell that my VB knowledge is cobbled together? 😀).
 
Back
Top