Qbasicnews.com
what's the point of type definition? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: what's the point of type definition? (/thread-1218.html)

Pages: 1 2 3 4


what's the point of type definition? - potato - 06-17-2003

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?


what's the point of type definition? - toonski84 - 06-17-2003

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.


what's the point of type definition? - seph - 06-17-2003

If I am to understand correctly jofers, types in QB are the equivalent of classes in C++?


what's the point of type definition? - [Unknown] - 06-17-2003

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]


again. - Agamemnus - 06-17-2003

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")


what's the point of type definition? - wizardlife - 06-17-2003

Quote:"]More like... wannabe structs. Minus some stuff. But yeah.

lol. Well put. A class is far more powerful than a mere TYPE.


Reply to Potato re Whats the point of TYPE definitions - Moneo - 06-18-2003

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.
*****


They're useful for keeping parameter/call lists... - Glenn - 06-18-2003

in SUB/CALL statements from being unwieldy.


what's the point of type definition? - aetherfox - 06-18-2003

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".


what's the point of type definition? - wizardlife - 06-19-2003

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...