1

I have a VB6 program that is failing on a particular machine.

The nature of the problem is code like this:

'this next line throws Type mismatch exception
If xml_file.documentElement.selectSingleNode("Node").Attributes.getNamedItem("InUse").nodeTypedValue Then
  'do some stuff
End If

The program uses MSXML4, and this problem only occurs on one machine (so far), though it works on many other machines. Furthermore, the InUse attribute is defined in the XML schema as follows:

<xs:attribute name="InUse">
    <xs:simpleType>
        <xs:restriction base="xs:boolean">
            <xs:whiteSpace value="collapse"/>
        </xs:restriction>
    </xs:simpleType>
</xs:attribute>

One more thing.

If I print out TypeName() of that .nodeTypedValue expression, it comes back as a "String". It's not terribly surprising, then, that a type mismatch might occur. But why only on that one machine?

As I'm thinking about it, that machine may have the Locale set to a different language than the other machines that I'm testing. Could that have something to do with it? Does VB6 use the locale determine how to coerce the string "false" into a boolean? If so, is there any way to force it to use English?

Any ideas?

Stringfellow
  • 43
  • 1
  • 8

1 Answers1

1

Yes, many type conversion functions and implicit conversions are locale-aware. For reliable operation in a case like this (in particular with XML) use:

If LCase$(Trim$(string-expression)) = "true" Then

XML schemas are fairly "soft" creatures. You might want to look at:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms762308(v=vs.85).aspx

Basically MSXML 4.0 is obsolete and not meant to be used anymore. Even then you need an XDR schema to get stronger typing. As of MSXML 6.0 XDR is not supported.

Effectively you ought to be using .nodeValue and just dealing with it.

Bob77
  • 13,167
  • 1
  • 29
  • 37
  • Thanks, Bob. Sure enough, the locale change was the issue. Looks like we've got a lot of refactoring to do in order support different locales, since there are lots of these implicit conversions. – Stringfellow Feb 24 '12 at 18:34
  • If you use an appropriate XSD then .nodeTypedValue still works, however MSXML does not support the full range of types so you can end up crashing on things like dateTime.rfc1123 items. – Bob77 Feb 26 '12 at 04:43