473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I press a command button in code?

In VB6 all you needed to do was set the name of the command button to True
like:

cmdGo = True

but this does not work in vb.net

Is there a code sample that shows how to do this?
Nov 21 '05 #1
13 9847
"Darrell Wesley" <Da***********@discussions.microsoft.com> schrieb:
In VB6 all you needed to do was set the name of the command button to True
like:

cmdGo = True

but this does not work in vb.net


\\\
Me.Command1.PerformClick()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Hello Darrell,

For calling a button press event pass all the required parameters: here is
an example:

Command1_click(nothing,nothing) 'We are passing nothing becasue we dont want
nothing to be passed.

If you want to pass some parameters you may do here.

I hope this is helpful

Thanks
Mona
[Grapecity]

"Darrell Wesley" <Da***********@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
In VB6 all you needed to do was set the name of the command button to True
like:

cmdGo = True

but this does not work in vb.net

Is there a code sample that shows how to do this?

Nov 21 '05 #3
Mona,

"Mona" <mo**@discussions.com> schrieb:
For calling a button press event pass all the required parameters: here is
an example:

Command1_click(nothing,nothing) 'We are passing nothing becasue we dont
want
nothing to be passed.


I recommend to pass the "correct" parameter values in order to prevent
unforseeable problems from occurring if the event handler accesses its
parameter's values in future. To do so, pass a reference to the control
raising the event in the first paramter and 'EventArgs.Empty' in the second
parameter in the case of the 'Click' event.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
In VB 6.0 you didn't need to invoke the event, nor do you need to in VB
..NET. In both (VB 6.0 and in VB .NET), you simply call the event handler
and pass the appropriate parameters.
"Darrell Wesley" <Da***********@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
In VB6 all you needed to do was set the name of the command button to True
like:

cmdGo = True

but this does not work in vb.net

Is there a code sample that shows how to do this?

Nov 21 '05 #5
Yeah. I agree with Herfried using PerformClick()

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #6
Darrel,
\\\
Me.Command1.PerformClick()
///


Be aware that with this, you can come in big problems later when you or
somebody else has to change the program.

If somebody has made it temporaly not visible or disabled it, than
perform.click will not fire. Mostly it is not so obvious in code that this
is done in another section.

I hope this helps,

Cor
Nov 21 '05 #7
Herfried,
I recommend to pass the "correct" parameter values in order to prevent
unforseeable problems from occurring if the event handler accesses its
parameter's values in future. To do so, pass a reference to the control
raising the event in the first paramter and 'EventArgs.Empty' in the
second parameter in the case of the 'Click' event.


I think that I have seen this messages from you about 100 times, can you
show us a sample of a future use that can have this effect.

To prevent your showed problem than simple syntax as this in the event is
more than enough (if there is a change that what you wrote can eventually
happen of course).
\\\
If Not Sender is Nothing then
'do every special things that is not general for a raiser of this
routine.
End if
///

I am curious for your sample where this above don't prevent any problem in
future and is not documentive enough?

Cor
Nov 21 '05 #8
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
I recommend to pass the "correct" parameter values in order to prevent
unforseeable problems from occurring if the event handler accesses its
parameter's values in future. To do so, pass a reference to the control
raising the event in the first paramter and 'EventArgs.Empty' in the
second parameter in the case of the 'Click' event.


I think that I have seen this messages from you about 100 times, can you
show us a sample of a future use that can have this effect.

To prevent your showed problem than simple syntax as this in the event is
more than enough (if there is a change that what you wrote can eventually
happen of course).
\\\
If Not Sender is Nothing then
'do every special things that is not general for a raiser of this
routine.
End if
///

I am curious for your sample where this above don't prevent any problem in
future and is not documentive enough?


Have you ever seen somebody checking if 'sender' is 'Nothing'?! If you are
not invoking the event handler maually by passing 'Nothing' in its
parameters, it's guaranteed that 'sender' and 'e' are references to objects.
No need to check if a null-reference has been passed to the method.
Consequently I would not change this behavior. Personally, I consider it
bad style to pass 'Nothing' in the standard event handler's parameters
because it breaks the event handling pattern.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
\\\
Me.Command1.PerformClick()
///


Be aware that with this, you can come in big problems later when you or
somebody else has to change the program.


Mhm... Wouldn't that apply to /every/ method you are using in your code?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #10
>Personally, I consider it bad style to pass 'Nothing' in the standard event
handler's parameters because it breaks the event handling pattern.

Which you are breaking even harder because if the event is not a "click
event" you suggest not to pass nothing. You pretend that you send forever
events and you are only doing that partially. Because that you are than not
consequent is there in my opinion a much harder change on wrong code.

Just my thought,

Cor
Nov 21 '05 #11
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
Personally, I consider it bad style to pass 'Nothing' in the standard
event handler's parameters because it breaks the event handling pattern.

Which you are breaking even harder because if the event is not a "click
event" you suggest not to pass nothing.


That's not true. I simply do not suggest to pass 'EventArgs.Empty' in the
event's second parameter, because sometimes a more specific type is
required.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12
Herfried,
That's not true. I simply do not suggest to pass 'EventArgs.Empty' in the
event's second parameter, because sometimes a more specific type is
required.

This passing of EventArgs.Empty is in my opinion more worse, it suggest that
there is an argument and than it is empty. With 'sender Is nothing' I am
sure that because I use forever the same passing signature in this
situations that there is as well no event.

Although I have showed you that I have used passing of 'me'. This threads
shows me that I should avoid that in future.

Just my thought,

Cor
Nov 21 '05 #13
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
That's not true. I simply do not suggest to pass 'EventArgs.Empty' in
the event's second parameter, because sometimes a more specific type is
required.

This passing of EventArgs.Empty is in my opinion more worse, it suggest
that there is an argument and than it is empty.


For the 'Click' event, the 'e' parameter contains a reference to
'EventArgs.Empty' by default. So passing 'EventArgs.Empty' is OK. For
other event handlers it's better to pass a more appropraite event arguments
object, as I already stated.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: MLH | last post by:
In Access 97 and Access 2.0 applications, if a command button has the focus, the spacebar will 'PRESS" the key. How does one go about disabling this annoying BEATURE?
6
by: Blue Bell Trading - Customer Services | last post by:
Hi, I have a text box, when a user presses enter I wish for the event on a command button on the form to be performed -- Kind Regards, Customer Services Blue Bell Trading
22
by: Ricky W. Hunt | last post by:
First, the subject probably doesn't use the correct terms but I'm not sure what it's called in VB. I'm writing a media player app. The subroutine that handles the "open file" button contains an...
0
by: neeraj | last post by:
Hi Everybody I have one problem in my asp.net web application. The problem is that I check the date validation in code behind; if user not gives the valid data and press save button then I fire...
3
by: gilbert3b2g | last post by:
I'm new to Python, and programming in general. What I'm trying to do here is to load a list of accounts from a file on my harddrive into a string of Buttons in Tkinter, and when I press one of the...
3
by: fieldling | last post by:
I've got a command button on a form that I would also like to work if I press, for example, F5. (Sounds pointless having a command button I know but there you go). I've tried using the On Key...
6
by: Dan2kx | last post by:
Hello again... just a quicky (hopefully) How do you set a command button's "special effect" to be sunk... using VB code. i have 3 buttons that i want to "sink" the active button for the one...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
3
by: Oriane | last post by:
Hi there, I would like to use a asp:Button to command a blind: when I press the Up button, the blind is opening, when I release the button, the blind stops. So I would like to send two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.