-
Dec 24th, 2011, 02:32 PM
#1
Thread Starter
Member
A command button you have to click
Hi friends,
I have a question about sub procedurs
I have a three command buttons called "command1, command2, command3"
I want user has to click command1 and command2 to be able to click command3
How can I do this?
Thanks
-
Dec 24th, 2011, 02:39 PM
#2
Re: A command button you have to click
Disable command3. Then the command1 & command2 click events...
Code:
Private Sub Command1_Click()
command3.tag = Val(command3.tag) Or 1
If Val(command3.Tag) = 3 Then
command3.tag = ""
command3.Enabled = True
End If
End Sub
Private Sub Command2_Click()
command3.tag = Val(command3.tag) Or 2
If Val(command3.Tag) = 3 Then
command3.tag = ""
command3.Enabled = True
End If
End Sub
-
Dec 24th, 2011, 02:41 PM
#3
Re: A command button you have to click
Can you explain a bit more?
-
Dec 24th, 2011, 02:47 PM
#4
Re: A command button you have to click
Merkez
An alternative approach ..
Code:
Public didButton1 as Boolean
Public didButton2 as Boolean
Private Sub Command1_Click()
didButton1 = True
End Sub
Private Sub Command2_Click()
didButton2 = True
End Sub
Private Sub Command3_Click()
If Not didButton1 Or Not didButton2 Then
Exit Sub
Else
' <do something>
End If
End Sub
Spoo
-
Dec 24th, 2011, 02:48 PM
#5
Thread Starter
Member
Re: A command button you have to click
Originally Posted by LaVolpe
Disable command3. Then the command1 & command2 click events...
Code:
Private Sub Command1_Click()
command3.tag = Val(command3.tag) Or 1
If Val(command3.Tag) = 3 Then
command3.tag = ""
command3.Enabled = True
End If
End Sub
Private Sub Command2_Click()
command3.tag = Val(command3.tag) Or 2
If Val(command3.Tag) = 3 Then
command3.tag = ""
command3.Enabled = True
End If
End Sub
Thanks for replying LaVolpe.. If you tell the idea, I will appreciate you.
RhinoBull
I have three command buttons. If the user don't click two of them, he won't be able to click third one. There is a must
-
Dec 24th, 2011, 02:54 PM
#6
Re: A command button you have to click
Originally Posted by _MeRKeZ_
Thanks for replying LaVolpe.. If you tell the idea...
The idea is to use bit masking to determine if both buttons were pressed. Bit masking and bitwise operations are valuable to learn in programming. There are many topics on this within this forum and you can google for more if desired.
-
Dec 24th, 2011, 03:06 PM
#7
Thread Starter
Member
Re: A command button you have to click
Spoo and LaVolpe,
It works. Thank you very much for helping.
-
Dec 24th, 2011, 03:14 PM
#8
Re: A command button you have to click
Originally Posted by _MeRKeZ_
I have three command buttons. If the user don't click two of them, he won't be able to click third one. There is a must
Simpler way [I think] would be to enable each subsequent button and disabling the rest of them:
Code:
Option Explicit
Private Sub Form_Load()
EnableButton Command1
End Sub
Private Sub Command1_Click()
EnableButton Command2
End Sub
Private Sub Command2_Click()
EnableButton Command3
End Sub
Private Sub Command3_Click()
EnableButton Command1
End Sub
Private Sub EnableButton(btn As CommandButton)
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is CommandButton Then
ctl.Enabled = False
End If
Next ctl
btn.Enabled = True
End Sub
-
Dec 26th, 2011, 12:16 AM
#9
Junior Member
Re: A command button you have to click
I am not a pro at programming but the way I would do it is like this for example...
Code:
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = False
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
If Button2.Enabled = False Then
Button3.Enabled = True
Else
Button3.Enabled = False
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Button2.Enabled = False
If Button1.Enabled = False Then
Button3.Enabled = True
Else
Button3.Enabled = False
End If
End Sub
And have button3 disabled by default.
-
Dec 26th, 2011, 09:34 AM
#10
Frenzied Member
Re: A command button you have to click
the simplest method is as descibed by spoo
a series of global flags that when set enable the button to know it can be pressed
enabling button3 on pressing b1 when b2flag=true and/or enabling button3 on pressing b2 when b1flag=true would be common practice
the use of the OR in the first example by lavolpe would confuse a newbie unless they had a good grasp of boolean logic which we cannot assume
the negative statment from spoo if not or not then exit can also be very disorientating for a newbie
both of them are correct but,
simple statements however clumbsy can help the newbie a lot
here to talk ( and to moan a bit )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|