3

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?

  • 2
    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 - on strike Jan 21 '11 at 09:25
  • As what type is 'obj' declared? – jakdep Jan 21 '11 at 09:37
  • obj is a custom type and property is a string property. –  Jan 21 '11 at 09:40
  • 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 - on strike Jan 21 '11 at 09:58

4 Answers4

3

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.

Bob Bowie
  • 31
  • 3
2

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
    I'd be very curious to know what's causing this, as well. I'm glad you figured out the culprit, though. I'll actually be able to sleep tonight. Of course, the fact that running under XP Mode causes VB 6 to flag this as an error makes me wonder if *everyone* who still writes VB 6 code should be forced to develop under XP Mode... – Cody Gray - on strike Jan 21 '11 at 10:25
  • I have the same problem trying to assign a string to a string while in a XP virtual machine. – Jeff LaFay Jul 01 '11 at 13:26
1

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

wqw
  • 11,771
  • 1
  • 33
  • 41
0

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....

Rob Cowell
  • 1,610
  • 3
  • 18
  • 34
  • I have tried obj.property = "True" and that works fine. However, I can't just change the code if it is working for everyone else in the company. –  Jan 21 '11 at 09:25
  • obj.property = true and obj.property="True" are not the same thing. One is a boolean check, the other is a string value check – Rob Cowell Jan 21 '11 at 09:28
  • That is true. For some reason when everyone else runs the code IF obj.property THEN is casting obj.property(string) to a boolean value. For me it is not, of course obj.property = "True" will return a boolean value on the = operator since it is a string. For everyone else it is like it is doing some automatic casting/converting of obj.property to a boolean value –  Jan 21 '11 at 09:30