Ask Your Question

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

asked 2018-11-05 17:11:25 +0200

PhLo gravatar image

updated 2018-11-05 17:16:06 +0200

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.

edit retag flag offensive close merge delete


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!

PhLo gravatar imagePhLo ( 2018-11-05 17:21:49 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-11-05 17:22:45 +0200

DrewJensen gravatar image

updated 2018-11-05 17:23:14 +0200

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.

edit flag offensive delete link more


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.

PhLo gravatar imagePhLo ( 2018-11-18 06:32:32 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-11-05 17:11:25 +0200

Seen: 332 times

Last updated: Nov 05 '18