Base oEvent AS OBJECT plus other passed parameters to Function or Sub

I’m hitting a wall with the oEvent AS OBJECT parameter passing to a sub or function.

I have successfully used the parameter to refer to an active button or control. That’s understandable, and it works.

However, can I also pass OTHER arguments to the same function or sub which receives the oEvent? For example:

functionName(oEvent AS OBJECT, sFirstName AS STRING, sLastName AS STRING)

Every time I try to add any other parameters, an error message pops:

Message: wrong number of parameters!

It’s horrifically annoying beyond all reckoning and imagination! It almost seems like an either/or situation. Either you write a function with multiple parameters OR you write it with one parameter, the oEvent. If this is true, it SEVERELY limits the functionality of any function or sub that needs to use the oEvent AND receive other parameters. By definition, a function is supposed to receive input and give an output. If it can’t receive input, it’s completely useless! I can’t imagine this is true, otherwise functions and subs don’t allow reuse of code (defeating their purpose). I’m a tad novice with this form of Basic, so maybe I’m missing something.

The more I think about it, it feels like one of those mind-bending chicken before the egg situations. I hate when I get these mind blocks. I guess I should expect it when I stay up all night!

To things come to mind.

First, make the last two parameters optional. See Basic Help - Optional function parameters

Second, the OEvent object includes a parent attribute, which gives you access to the object (a button, a grid cell, etc) which held focus when the event triggered. Your script can examine the values held by attributes of those objects, or even by reference to other objects associated with it.

Thanks. I have since been writing macros differently so I don’t have to pass parameters into functions that also rely on the oEvent situation. It can be a little tricky, but it seems possible to do one or the other in most situations. I also do what you mentioned, where I inspect the model and parents to get elsewhere. Good tips.