Skip to content

Raise Your Events The Right Way

The other day I was asked: “Dumb question of the day! An Event Definition can have a Return Type defined. What is the syntax for RaiseEvent to make use of the Return Type?”

But this isn’t a dumb question at all since there are actually two valid ways to do this. I find one more obvious than the other. Here are both solutions so you can decide for yourself:

The first is to use it just like any other function you write.

Say you add an event definition “GetHeight” that returns an Integer. You could write code that looks like this:

dim h as integer = GetHeight( parameters )

Just like any FUNCTION.

The other way you can write this is to use the RaiseEvent command:

dim h as integer = RaiseEvent GetHeight( parameters )

I think this second option makes it clearer that you are using an event, not a method, like a function and expecting a return value. There really are no dumb questions, and asking them on the Xojo Forums can help you and others in the community learn best practices.