Results 1 to 10 of 10

Thread: A command button you have to click

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    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

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    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

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    Re: A command button you have to click

    Quote Originally Posted by LaVolpe View Post
    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

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: A command button you have to click

    Quote Originally Posted by _MeRKeZ_ View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    Re: A command button you have to click

    Spoo and LaVolpe,

    It works. Thank you very much for helping.

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: A command button you have to click

    Quote Originally Posted by _MeRKeZ_ View Post
    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

  9. #9
    Junior Member d.crozier7's Avatar
    Join Date
    Dec 2011
    Location
    United States
    Posts
    28

    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.

  10. #10
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    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
  •  



Click Here to Expand Forum to Full Width