"Assigns" used with RaiseEvent?

I just discovered that this syntax doesn’t appear to work:

RaiseEvent NowPlayingProgress = 35

Whereas this works:

RaiseEvent NowPlayingProgress(35)

I must be missing something. Can anyone enlighten me as to what is going on in the background that prevents the first syntax from working?

Why should an assignment work here?

1 Like

The way this is traditionally done is to create a method of the same name with an Assigns parameter, and have that method raise the event.

I suppose I wasn’t verbose enough. When creating an “Event Definition” you can also create a parameter list. If I apply the “assigns” keyword to the first parameter (as you can when creating a method) it appears that this syntax does not work.

Event Name: NowPlayingProgress

Parameters: Assigns NewPercentage As Integer

My understanding is that this definition should allow me to use the syntax:

RaiseEvent NowPlayingProgress = 35

What happens if you leave off RaiseEvent? (Assuming you don’t have another method or property of the same name.)

Wow… that was surprising. If I remove the RaiseEvent keyword the compiler stops complaining and the code works as expected.

On the one hand, maybe I’m overly picky but I like the extra information conveyed by the presence of the RaiseEvent keyword. On the other hand I also think that NowPlayingProgress = 35 conveys the intent of the operation better than NowPlayingProgress(35) does.

But it appears that I can’t have both. I wonder why?

You’re right, you’re being overly picky.

:smiley:

That may be. But doesn’t this fly in the face of the highly honored “principle of least surprise”?

I’d guess the compiler was just never set up to allow that syntax after the RaiseEvent keyword, probably because it reads a bit awkwardly.

2 Likes