VBA class property bug CATIA V5R27 64 bits

Ludovic WAGNER

VBA class property bug CATIA V5R27 64 bits


I'm currently developping a project in VBA and I noticed the following bug :

If I have a property exist which returns a boolean of a class myClass.  The following expression is mis-evaluated :

Dim myObj As New myClass: If myObj.exist Then debug.print ".. is evaluated to True even if exist does return False"

Note that If Not myObj.exit Then.. is identical to If myObj.exist Then..Using a Function instead of a Property Get has no difference, but it solved the issue if I declare a temporary variable

Dim flag As Boolean: flag = myObj.exit

If flag Then debug.print ".. is only evaluated if flag = True"

Of course, this alternative is not acceptable as it eventually requires many temporary variable.

Note that I didn't have this issue in CATIA V5R21 32 bits, nor in Excel (both 32 and 64 bits). Unfortunately, I haven't managed to reproduce this issue on a basic set of instructions (I have over quite a few classes). Does anyone have an idea about this issue ?

Thanks :-)

Cliff Johnson, Cliff

RE: VBA class property bug CATIA V5R27 64 bits
(in response to Ludovic WAGNER)

Without seeing at least the code of your "Exists" property it is not possible to draw a conclusion. 

However, one thing to watch out for are Boolean value returned by any CATIA API property or method. These must be treated suspiciously. CATIA returned Boolean values are generally not exactly compatible with VBA Boolean values. 

So if your Exists property determines it's value by evaluating any Boolean value returned by a CATIA API call, that could be the problem. 

Anytime I work (in VBA) with Boolean values returned by CATIA methods or properties I will convert it to a true VBA Boolean type by doing this:  

    Dim someValue as Boolean
    someValue = cbool(cint(oCATIAObject.SomeBooleanMethod()))


How to ask questions 

Ludovic WAGNER

RE: VBA class property bug CATIA V5R27 64 bits
(in response to Cliff Johnson, Cliff)

Thank you for your reply. I eventually read in "Support of boolean type in CATVBA" of the CATIA Automation documentation that the issue comes from type differences : Unsigned Chart (V5 API) vs. Short (VBA). I don't think it actually comes from any V5 API output in my case, but rather from "VBA class featuring a function that returns a boolean". I think that using Variant instead of Boolean type fixes the issue, but I need to check further.

PS. One of my colleagues  also gave me the cBool(cInt(...)) tip, but it had no effect.