473,549 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 41759
You might try something along the lines below where you name the buttons
But1, But2, etc:

Private Sub button_Click(By Val sender As System.Object, ByVal e As _
System.EventArg s) Handles button1.Click, button2.Click, button3.Click, _
button4.Click, button5.Click, button6.Click
Select Case DirectCast(send er,button).Name
Case "but1"
button_Click (Me.but1, e)
Case "but2"
but5.Enabled=Tr ue:but9.Enabled =True
but6.Enabled=Fa lse:but6.Enable d=False
case "but3"
but5.Enabled=Tr ue:but6.Enabled =True
but5.Enabled=Fa lse:but9.Enable d=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********@hot mail-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.perform click()
end if

Bernie Yaeger

"code100579 " <ro********@hot mail-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(By Val sender As System.Object, ByVal e As _
System.EventArg s) Handles button1.Click, button2.Click, button3.Click, _ button4.Click, button5.Click, button6.Click
Select Case DirectCast(send er,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(By Val sender As System.Object, ByVal e As _
System.EventArg s) Handles button1.Click, button2.Click, button3.Click,
_
button4.Click, button5.Click, button6.Click
Select Case DirectCast(send er,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(By Val sender As System.Object, ByVal e As _
System.EventArg s) Handles button1.Click, button2.Click, button3.Click, _ button4.Click, button5.Click, button6.Click
Select Case DirectCast(send er,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(By Val sender As System.Object, ByVal e As _
System.EventArg s) Handles button1.Click, button2.Click, button3.Click,
_
button4.Click, button5.Click, button6.Click
Select Case DirectCast(send er,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
4210
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 like that same button to fire its event when the user presses enter. Can anybody help with this? *** Sent via Developersdex...
0
1120
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: function SaveForm(btnName) { alert('Save Form click ' + btnName); var btn = document.forms; btn.click();
2
9023
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 object (both the HTML and control are built in the same .ascx file) The target button simply fires an event in the WebUserControl-derived object. So,...
5
8051
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 allbuttonsclick (ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click,...
2
3859
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 interogating the sender)? -- mark
2
7702
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 submit button to submit a form that contains one or two Mileposts: 1) If a Milepost range larger than 5 miles is entered, I would like to pop...
5
5779
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 pressed it removes the check but does not re-hide the submit <div> bit. The way i see it, I have 3 options: 1) To simply remove the clear for...
4
5634
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 error "error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types." I have tried deleting...
2
4811
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: - I have an ASPX page with a SqlDataSource control with Select, Update and Delete calls to stored procedures and a GridView bound to SqlDataSource, ...
0
7551
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7477
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7750
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7991
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1084
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.