472,330 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

How to put a button click in an if statement?

Hi there, sorry if this is a really simple question.
I need to write code for:

If a button is pushed and then one variety of other buttons is pushed
then certain options on the program will become "greyed out". Ie they
can no longer be selected.

I assume i need to create an event from the first button being pushed
and then do if statements depending which button is pushed next

(IE. First Button is pushed,
If Button 2 is pushed then
buttons 6 and 8 become unusable
Else If Button 3 is pushed then
buttons 5 and 9 become unusable)

The problem i have is how do u put a button click in an if statement?
Please Please help.....this is driving me mad!
Kind Regards,
Code
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 21 '05 #1
7 41077
You might try something along the lines below where you name the buttons
But1, But2, etc:

Private Sub button_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles button1.Click, button2.Click, button3.Click, _
button4.Click, button5.Click, button6.Click
Select Case DirectCast(sender,button).Name
Case "but1"
button_Click (Me.but1, e)
Case "but2"
but5.Enabled=True:but9.Enabled=True
but6.Enabled=False:but6.Enabled=False
case "but3"
but5.Enabled=True:but6.Enabled=True
but5.Enabled=False:but9.Enabled=False
buttons 5 and 9 become unusable)
End Select
End Sub

"code100579" wrote:
Hi there, sorry if this is a really simple question.
I need to write code for:

If a button is pushed and then one variety of other buttons is pushed
then certain options on the program will become "greyed out". Ie they
can no longer be selected.

I assume i need to create an event from the first button being pushed
and then do if statements depending which button is pushed next

(IE. First Button is pushed,
If Button 2 is pushed then
buttons 6 and 8 become unusable
Else If Button 3 is pushed then
buttons 5 and 9 become unusable)

The problem i have is how do u put a button click in an if statement?
Please Please help.....this is driving me mad!
Kind Regards,
Code
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 21 '05 #2

"code100579" <ro********@hotmail-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
Hi there, sorry if this is a really simple question.
I need to write code for:

If a button is pushed and then one variety of other buttons is pushed
then certain options on the program will become "greyed out". Ie they
can no longer be selected.

I assume i need to create an event from the first button being pushed
and then do if statements depending which button is pushed next

(IE. First Button is pushed,
If Button 2 is pushed then
buttons 6 and 8 become unusable
Else If Button 3 is pushed then
buttons 5 and 9 become unusable)

The problem i have is how do u put a button click in an if statement?
Please Please help.....this is driving me mad!
Kind Regards,


OK, this may well not be the best way, but here are a couple of
possibilities...
From your description, buttons 2 and 3 have no functionality unless button 1
has been clicked, correct?
Disable buttons 2 and 3, and enable them in code only when button 1 is
clicked, then when the user clicks either 2 or 3, do as you've stated.
If buttons 2 and 3 *do* have associated functionality independent of button
1, consider making them fully independent and using, say, radio buttons
(enabled when the user clicks button 1) to allow the user make the choice
between which other buttons are enabled/disabled.
Or, you could use a class level variable to indicate that button one has
been clicked and test the variable in the event procedures for buttons 2 and
3. A Boolean would work well here. Set it in the event procedure for button
1, then be sure to housekeep the variable, once used, in the event
procedures for buttons 2 and 3.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 21 '05 #3
Hi,

Did you try the button's performclick() method?

if .....
button1.performclick()
end if

Bernie Yaeger

"code100579" <ro********@hotmail-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
Hi there, sorry if this is a really simple question.
I need to write code for:

If a button is pushed and then one variety of other buttons is pushed
then certain options on the program will become "greyed out". Ie they
can no longer be selected.

I assume i need to create an event from the first button being pushed
and then do if statements depending which button is pushed next

(IE. First Button is pushed,
If Button 2 is pushed then
buttons 6 and 8 become unusable
Else If Button 3 is pushed then
buttons 5 and 9 become unusable)

The problem i have is how do u put a button click in an if statement?
Please Please help.....this is driving me mad!
Kind Regards,
Code
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 21 '05 #4
> Private Sub button_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles button1.Click, button2.Click, button3.Click, _ button4.Click, button5.Click, button6.Click
Select Case DirectCast(sender,button).Name
Case "but1"
button_Click (Me.but1, e)


This will cause a stack overflow as you will continue to execute this
code over and over.

Nov 21 '05 #5
I suggest something similar to what Dennis suggested.

'Boolean variable to indicate if Button1 is pushed
Public bButton1Pushed As Boolean

Private Sub button_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles button1.Click, button2.Click, button3.Click,
_
button4.Click, button5.Click, button6.Click
Select Case DirectCast(sender,button).Name
Case "but1"
bButton1Pushed = True
Case "but2"
If bButton1Pushed Then
but6.Enabled = True
but8.Enabled = True
bButton1Pushed = False 'Reset the variable for the
next time
Else
'Code to run if Button1 wasn't pushed first
End If
case "but3"
If bButton1Pushed Then
but5.Enabled = True
but9.Enabled = True
bButton1Pushed = False 'Reset the variable for the
next time
Else
'Code to run if Button1 wasn't pushed first
End If
End Select
End Sub

Nov 21 '05 #6
> Private Sub button_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles button1.Click, button2.Click, button3.Click, _ button4.Click, button5.Click, button6.Click
Select Case DirectCast(sender,button).Name
Case "but1"
button_Click (Me.but1, e)


This will cause a stack overflow as you will continue to execute this
code over and over.

Nov 21 '05 #7
I suggest something similar to what Dennis suggested.

'Boolean variable to indicate if Button1 is pushed
Public bButton1Pushed As Boolean

Private Sub button_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles button1.Click, button2.Click, button3.Click,
_
button4.Click, button5.Click, button6.Click
Select Case DirectCast(sender,button).Name
Case "but1"
bButton1Pushed = True
Case "but2"
If bButton1Pushed Then
but6.Enabled = True
but8.Enabled = True
bButton1Pushed = False 'Reset the variable for the
next time
Else
'Code to run if Button1 wasn't pushed first
End If
case "but3"
If bButton1Pushed Then
but5.Enabled = True
but9.Enabled = True
bButton1Pushed = False 'Reset the variable for the
next time
Else
'Code to run if Button1 wasn't pushed first
End If
End Select
End Sub

Nov 21 '05 #8

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

Similar topics

3
by: Philip Townsend | last post by:
I have an aspx page that contains 2 user controls, each containing a seperate textbox and button. I would like to specify that one of the buttons...
0
by: H Branyan | last post by:
Scenario: When a user submits the form by clicking one button (ButtonA), I want to fire the click event for another button (ButtonB). I...
2
by: JCE | last post by:
I need to programmatically invoke an asp:Button click event from a javascript function. The page containing the script and the button is the HTML...
5
by: Antonio Policelli | last post by:
hello, i want to have 10 buttons on a form and all will do almost exactly the same thing except for one differnece. can i use the tag property of...
2
by: mark | last post by:
Is there a means of raising an event when ANY button on a windows application form is clicked wherein the actual button clicked can be determined in...
2
by: bay_dar | last post by:
Hi, I have an internal ASP.NET application that I'm are using to send e-mails out based on a single milepost or milepost range entered. I'm...
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The...
4
by: Dennis | last post by:
I have a page in ASP.NET 2.0. I add a button in design view and the page runs fine. I then double-click the button to create the click method in...
2
by: Hrvoje Vrbanc | last post by:
Hello all! As I have only recently started to use native ASP.NET 2.0 data access controls (and found them to be very powerful), I have one...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

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.