Skip to main content
gamedev.net
🔒 Locked

Comparing types.

Started by STufaro 2 replies 750+ views
Original Post
STufaro
STufaro
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.
DaedalusOwnsYou
DaedalusOwnsYou
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 =.
STufaro
STufaro
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.
XTAL256
XTAL256
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.
[Window Detective] - Windows UI spy utility for programmers

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.