Archived

This topic is now archived and is closed to further replies.

why the New in objDX8 as new DirectX8?

This topic is 5775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Without going into the sticky details, well suffice to say this. Classes need to have New in their declaration.(Not ALWAYS true, but for beginning VB its ok) Types and Vars dont, jsut classes.

An explanation why can be given if you want.

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Democracy is where you say what you want and do what you''re told.

Share this post


Link to post
Share on other sites
The NEW keyword in Visual Basic is how you create a new instance of a class. A class is distinctly different than a Variable in VB.

If CMyClass were a class object you created, consider the following:

Dim mcDemo as CMyClass
Dim intTemp as Integer

A Variable is just an easy way to represent a place in memory, right? We, as programmers, reference by variable because it makes our life so much easier. The question of what is stored in that memory location is not one that VB programmers have to consider very often. In the case of an integer or string or whatever, the variable is a representation of the memory address where the data is stored. In the case of a class object, the variable is a representation of the memory address where ANOTHER memory address is stored. That second memory address is the address where the data is stored. You know the difference between ByRef and ByVal? If you took the ByVal of intTemp, you would get 7 or 9 or 232 or whatever was stored in the intTemp variable. If you took the ByVal of mcDemo, you would get a long address that would be meaningless to you.

When you use the NEW keyword, you actually dimension the memory for the instance of the class, so consider the following:

Dim mcDemo as New CMyClass

now, mcDemo contains a memory address that is the location of all of that CMyClass data. The NEW keyword is very important when working with any class object. You may notice alot of times if you Dim a variable for a collection, you cannot just use that varialbe like a collection object, you have to do something like:

Set dd7surf = DX7.CreateSurface(blahblahblah)

The Set keyword in that statement is important because it tells VB that you''re setting a class variable, not a regular variable. There is no NEW keyword, but there is a function (CreateSurface) that does the work the NEW keyword would normally do.

That was a little brief, any questions?

-Ben

Share this post


Link to post
Share on other sites