-
Mar 23rd, 2025, 06:48 PM
#1
Thread Starter
Addicted Member
[RESOLVED] calling a control from within the code to operate it
I'm trying to figure out how I would call a function within a function within VB Net. In VBA this is easy, but I have not figured out what arguments I would place into (e) in the function call.
Here is the VBA code, which is easy to call.
Code:
BTN_CREATE_TASK_Click()
Now in VB this is what the calling function looks like.
Code:
Private Sub BTN_CREATE_TASK_Click(sender As Object, e As EventArgs) Handles BTN_CREATE_TASK.Click
What do I fill (e) will before I call the function, or do I need to call it another way say SendMessage?
-
Mar 23rd, 2025, 07:22 PM
#2
Re: calling a control from within the code to operate it
 Originally Posted by FunkMonkey
I'm trying to figure out how I would call a function within a function within VB Net. In VBA this is easy, but I have not figured out what arguments I would place into (e) in the function call.
Here is the VBA code, which is easy to call.
Code:
BTN_CREATE_TASK_Click()
Now in VB this is what the calling function looks like.
Code:
Private Sub BTN_CREATE_TASK_Click(sender As Object, e As EventArgs) Handles BTN_CREATE_TASK.Click
What do I fill (e) will before I call the function, or do I need to call it another way say SendMessage?
If you want to call the event handler then for something as simple as a Click event you could just pass EventArgs.Empty as the click event doesn't expect anything useful there anyway.
However, I personally wouldn't call event handlers from other bits of code. If there is something that needs to be called from multiple places then I would put the code in it's own method and then call that from the Click event, or any other place you need to call it from.
If the other place you want to call this from is also a click event then you could have the one event handler respond to multiple events e.g.
Code:
Private Sub BTN_CREATE_TASK_Click(sender As Object, e As EventArgs) Handles BTN_CREATE_TASK.Click, Button2.Click
-
Mar 23rd, 2025, 08:09 PM
#3
Thread Starter
Addicted Member
Re: calling a control from within the code to operate it
 Originally Posted by PlausiblyDamp
If you want to call the event handler then for something as simple as a Click event you could just pass EventArgs.Empty as the click event doesn't expect anything useful there anyway.
However, I personally wouldn't call event handlers from other bits of code. If there is something that needs to be called from multiple places then I would put the code in it's own method and then call that from the Click event, or any other place you need to call it from.
If the other place you want to call this from is also a click event then you could have the one event handler respond to multiple events e.g.
Code:
Private Sub BTN_CREATE_TASK_Click(sender As Object, e As EventArgs) Handles BTN_CREATE_TASK.Click, Button2.Click
Thanks. Sounds like the best way to go is to create a seperate function. Much appreciated.
-
Mar 23rd, 2025, 09:09 PM
#4
Re: calling a control from within the code to operate it
That is considered good form.
My usual boring signature: Nothing
 
-
Mar 23rd, 2025, 09:29 PM
#5
Re: calling a control from within the code to operate it
It's worth noting that a Button control has a PerformClick method, so you can call that to have that Button raise its Click event and thus execute the event handler for that event. There generally aren't methods to raise events like that but Click for a Button is so common that they decided to add one for that. PD's suggestion is what you'll have to do for most other events, so you can do the same for a Button's Click event for consistency. As suggested, you should pretty much NEVER call an event handler directly in your own code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|