Sign in to follow this  
STufaro

Comparing types.

Recommended Posts

Hey guys - I'm in VB6 (but everything should be just about the same [except for some minor syntax] with other languages). I'd like to compare two things that are types (specifically two D3DMATERIAL8s) in an If-Then statement to prevent unneccessarily replicating them within my game engine. So I have: [CODE]If Material1 = Material2 Then...[/CODE] But when I go to run it, VB highlights the = sign and says "Type: mismatch", even though the are of the same type, D3DMATERIAL8. I AM, however, allowed to copy Material1 to Material2 like [CODE]Material2 = Material1[/CODE] I tried using "Is" as well to no avail. So I assume this is a problem that exists beyond just the Material types. I guess you can't compare ANY types then without comparing their individual elements separately? The D3DMATERIAL8 types are composed of D3DCOLORVALUE types, which themselves are composed of Singles. Maybe I can't compare the types because the types themselves are made up of other types? [B]So, bottom line: Is there a way I can compare types without comparing each of their individual elements? Why isn't this working and why am I getting a mismatch?[/B] Thanks! Much obliged, - Steve.

Share this post


Link to post
Share on other sites
Are you actually comparing the 2 objects like this:

if (Material1=Material2) {
//stuff
}


I'm not familiar with VB6, but, in C style languages a comparison is 2 = together, so that becomes

if (Material1==Material2) {
//stuff
}

A single = assigns the right to the left, so Material1 is becoming a copy of Material2. Oddly enough, this usually returns the variable being copied, so that statement can be used in an expression. In this case that's a material object. Because the compiler sees an if statement, and wants a boolean expression to go along with it, it's confused by the fact that you are putting a material there. That's why you can assign, but not compare, because you are still assigning!

Short version:
Try using == instead of =.

Share this post


Link to post
Share on other sites
Thanks for the reply!

I should have mentioned that the = and == are the same in VB6; not so with C languages.

The problem is that VB does not have any built-in way of comparing types, you either have to compare them element by element or use something described in this thread I started:

http://www.xtremevbtalk.com/showthread.php?t=298327

which basically provides a way to port the memcmp function to VB by substituting an API call.

Thanks again, though.

- Steve.

Share this post


Link to post
Share on other sites
I too don't know much about VB6 (although i did know that it doesn't use ==), but does the equality operator compare pointers like C/C++ or does it actually compare them element by element, which you seemed to say it didn't. All else failing, you could just write a function that compared each element.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this