Ambiguity between assignment = and equality =: where to get VBA BNF syntax? RRS feed

  • Question

  • Hi,

    I have a question with VBA equal sign =. It is both the equality comparison operator, as well as the assignment operator, so how does the parser resolve the ambiguity?

    In C, the two are distinct: equality (==) and assignment (=)

    In some other languages, the assignment is .

    It is possible to figure out several solutions the parser might have adopted, for example treating the first = sign in a pure, isolated expression  such as


    as assignment, and if in the condition block of IF-THEN statement then treat the first = sign as equality comparison. However I think a definitive official clarification from MS can be the only definitive one.

    I searched microsoft.com and found [MS-VBAL] - VBA Language Specification. However it didn’t contain syntactic rules. I am looking for the BNF form syntax rules of VBA, and the rules VBA used to adopted the ambiguity between assignment = and equality =.

    Please help,


    Thursday, August 9, 2012 12:42 PM

All replies

  • I think it is treated last in the PEMDAS chain. But if you have multiples =s to assign the result of a comparison say, then it can be an issue, so using parentheses is the solution.

    HTH, Bernie

    Thursday, August 9, 2012 12:57 PM
  • Bernie,

    I don't think so. Simple PEDMAS doesn't resolve it.

    Thursday, August 9, 2012 1:21 PM
  • VBA doesn't allow assignment in all the situations that, say, C does, so the conflict never arises and, AFAIK, there is no ambiguity.
    Assignment is achieved with either a Let or a Set statement (or, maybe, LSet or Rset, or, I suppose, Mid). All of these take the same essential form: (start of statement) [verb] receiver = source-data (end of statement), and none of them can appear where a condition can.

    Monday, August 27, 2012 11:19 AM