I've never used classes to define my variables. Excluding arrays, I just flat out use the variable. So why should I use the:
Code:
TYPE blah
blah.contents AS type
END TYPE
declarations? Does it speed up the program? Add a new feature?
It actually works like this:
type blah
attribute1 as integer
attribute2 as integer
attribute3 as integer
end type
such that you could do something like this
dim blah(10) as blah
blah(1).attribute1 = 10
blah(1).attribute2 = 5
type structures are very useful for organizational reasons, and having the benefit of making things like records or multiple types in a single array. They're used in other languages like C too.
If I am to understand correctly jofers, types in QB are the equivalent of classes in C++?
Quote:If I am to understand correctly jofers, types in QB are the equivalent of classes in C++?
More like... wannabe structs. Minus some stuff. But yeah.
-[Unknown]
types are good for making compact dim code, but the type format is for some unknown reason different than other formats. (yes, qb *can* recognize the difference even if they have the same format, and NO, qb forces you to add to a type say "mouse" if you already defined it, can't just say "DIM shared mouse.newvar as integer")
Quote:"]More like... wannabe structs. Minus some stuff. But yeah.
lol. Well put. A class is far more powerful than a mere TYPE.
Potato: I agree with you, I have the same feeling. I can't really find the advantage of TYPE's. I have written hundreds of production programs in QuickBasic, and the only time I used TYPE's was to conform to some function that I was using from a library or incorporating into my program.
I'm open to being enlightened as to its advantages.
*****
in SUB/CALL statements from being unwieldy.
Just down to organisation.
I honestly don't know the coding significance they may have, but as far as I have used them, it's been pretty much style. I DO use types, simply because I find it much easier to work with. Let's take the classic example of the RPG. Lovely World/Player/NPC type. Simplifies everything and makes stuff easy to understand and organise.
If you don't want to use it, I don't see why you should apart from the aforementioned "conforming".
The data structure support in QB is so poor that there really isn't a whole lot of point, but it's a good practise to get into for other languages. Once you move on, you will meet nested structures and tihngs called pointers and then you'll want user defined types for sure...