473,387 Members | 1,779 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 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 41677
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 recieve focus when the page loads. Also, I would...
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 created a javascript function first to the webform:...
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 page associated with a WebUserControl-derived...
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 each button in the same sub? private sub...
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 the generic click events code (eg by way of...
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 trying to do two things when a user clicks on the...
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 problem I have is when the clear form button is...
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 the code. Then when I run the page I get the...
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 question that I was unable to find the answer to: -...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.