Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi All,

I am trying to call a click routine such as
VB
btnVoltsCurrent_Click(sender, New System.EventArgs())

I have done this using another click routine which has some values passed to it, I am now trying to call from a Sub() that does not have the value passed to it.
Leaving with sender is not declared errors....
HELP!

Glenn
Posted
Comments
[no name] 11-Apr-14 12:45pm    
Have you tried btnVoltsCurrent_Click(Nothing, Nothing)?
glennPattonWork3 11-Apr-14 12:47pm    
Well no I hadn't, seems to work though... have a 5 on me! oh Dang I can't put it as answer I'll give you 5!!
Richard C Bishop 11-Apr-14 12:52pm    
Add as the solution!
glennPattonWork3 11-Apr-14 12:54pm    
Umm not sure how I do that!
Richard C Bishop 11-Apr-14 12:58pm    
That comment is for Wes Aday.

Your first mistake is that you have your code in the Click event handler. That's wrong. The code you have in there should be in its own method. That way, you can call the code from anywhere, including the Click event handler(!), and you don't have to worry about how you're going to call the code in there by passing garbage parameters to it.
 
Share this answer
 
Comments
glennPattonWork3 11-Apr-14 13:08pm    
If wish's were horses!
Dave Kreskowiak 11-Apr-14 13:12pm    
I wish the obvious wouldn't be so damned hard to find to sometimes! :)
glennPattonWork3 11-Apr-14 13:14pm    
You and me both brother!
Sergey Alexandrovich Kryukov 11-Apr-14 21:34pm    
Of course, a 5.
Still the question is better than many more typical questions on "how to call event".
—SA
Dave Kreskowiak 11-Apr-14 23:58pm    
I know it is. Plenty of context to work with. That's the nice part about it, though someone still voted it a one and that person has just as much pull around here as I do.
As David so rightfully pointed out that the correct way to do this is to pull out the code from the button click handler that you need to call from the other non-event driven method and put that into a separate method.

However, if you are pressed for time and need to do a quick and dirty test to see if it works, you could (and I am not saying that this is right) call your button click handler with dummy parameters.

VB
btnVoltsCurrent_Click(Nothing, Nothing)


But you can only do this if you do not need the sender or the event arg parameters.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Apr-14 21:35pm    
If you did not call it "quick and dirty" I would not like it... :-) My 5.
—SA
[no name] 11-Apr-14 21:48pm    
Thank you Sergey. I was actually thinking of you when I wrote it. :-)
Sergey Alexandrovich Kryukov 11-Apr-14 22:07pm    
Do you mean that you expected me to criticize the answer? I really would, but you did it yourself.
—SA
[no name] 11-Apr-14 22:30pm    
Oh yes. I knew that you would unless I qualified it enormously. :-) Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900