= and :=

M

Martyn Kemp

Hi,

I'm new to VBA and have noticed that there seem to be two different
symbols used for assignments, the equals sign for general assignments
and colon equals for assignments to named parameters. Why do there
need to be two different assignment symbols in VBA?

Thanks, Martyn
 
J

Jay Freedman

Why? Because the people who created VBA chose to make it easier for the parser to know what to do, while making it harder for you and every other VBA programmer, that's why.

When someone creates a parser or compiler, the most critical part of the job is defining the "state machine", the definition of all the possible states (declaring a variable, assigning a value,
defining a parameter, ending a statement, etc.) and all the valid transitions from one state to another upon reading the next input character. The VBA team decided that it would be easier to
distinguish the transitions if there was a special character-pair for named parameters. Other language creators made other choices. (Take a look at Pascal sometime.)
 
M

Martyn Kemp

Jay,

Thanks for taking the trouble to reply.

I have, thanks, and it is nice and clean (semantics/syntax-wise by
comparison). Been using Delphi since it was released, and Turbo +
Borland Pascal for years before that. Suddenly I have a need to get
to grips with VBA and that's why I asked the question. Why does VBA
need two different operators to signify assignment?

I'm sure that's the myth, but I don't buy it for a moment. The VBA
parser will far more frequently have to deal with the potential
ambiguity between the equals sign used as meaning "equal" and as LHS
should get the value of RHS (as in assignment). Why it should need to
treat assignment of named parameters differently is a bit of a
mystery.

Well, one can define a computer language using Lex + Yacc (and I have
many times), and the question of "easier" just doesn't arise. The
state-machine that Yacc constructs just handles the difference, if the
grammar is unambiguous. If it isn't unambiguous, then redefine the
language.

Anyway, the fact that language creators hand-coding a parser might
find it more difficult to deal with equals vs. assignment is not a
good reason to inflict it on the language's users. They would have
done better to avoid using the equals sign to mean assignment in the
first place.

Btw, I am absolutely not trying to start a flame war, I was just
curious what be the reason why VBA users would have to put up with
having two different flavours of assigment.

Cheers, Martyn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top