• 15
• 15
• 11
• 9
• 10

# Comparing types.

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

## 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: If Material1 = Material2 Then... 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 Material2 = Material1 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? 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? Thanks! Much obliged, - Steve.

##### 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 on other sites

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:

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

Thanks again, though.

- Steve.