3
votes

I am getting the following type mismatch error on the following

   IF obj.propery THEN
    ...
    END IF

the code I am using is on visual source safe and when other developers run the same project the code runs with no error. The property is actually a string which is where the problem could be. When I debug and test the property i.e.

?obj.propery = True

no errors are thrown which is a bit strange. If I place the cursor over the property it says "True". I have done a bit of searching on the matter and have found that this may have something to do with OPTION STRICT, however I have the same version of the code as the other developers and OPTION STRICT is not OFF, it hasn't been altered in the code at all. Are there any other settings that could affect this execution of code at run time?

4
There is no Option Strict in VB 6. The searching you've done has probably turned up VB.NET-related resources. It's not, erm, possible that the other developers are using VB.NET, is it?Cody Gray
As what type is 'obj' declared?jakdep
obj is a custom type and property is a string property.user322076
My original answer is apparently incorrect. I can now reproduce VB 6 coercing a String with the values "true"/"True" or "false"/"False" to a Boolean when testing the value with an if statement. As distressing as that is to me, it appears to be reality. You'll of course still get a compiler error if the string is set to something other than those two values. Can you try creating a brand new project in your copy of VB 6 and seeing if it does the same thing extracted from the larger code base?Cody Gray

4 Answers

3
votes

It strikes me that there could be an entirely different reason for your Type Mismatch error, especially as you are accessing an object property. I've experienced this error when I have, for some reason, been pointing at a different DLL to that registered. You will find with VB that it registers a DLL "on the fly" when you build it, so you may end up accessing the code somewhere that you did not expect. This may not be the problem in your case, but it is worth exploring.

2
votes

This was nothing to do with VB6, it was to do with XP Mode and using my user account from another domain as opposed to XPMUser. When I use XPMUser the application runs this is very odd and I am not sure why this is. If anyone has the reason I would love to hear.

1
votes

So you are sure this is not the case of a boolean being Vrai?

0
votes

I'd be inclined to be more explicit in your IF condition

IF isempty(obj.property) = false AND isnull(obj.property) = false

BUT

it would be prudent to check that obj isn't null first, before you start accessing its properties....