Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what's the point of type definition?
#1
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?
ammit potato!
Reply
#2
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.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#3
If I am to understand correctly jofers, types in QB are the equivalent of classes in C++?
earn.
Reply
#4
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]
Reply
#5
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")
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
Quote:"]More like... wannabe structs. Minus some stuff. But yeah.

lol. Well put. A class is far more powerful than a mere TYPE.
Reply
#7
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.
*****
Reply
#8
in SUB/CALL statements from being unwieldy.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#9
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".
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#10
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...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)