How to include a button click procedure in an if then statement?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Miller
    New Member
    • Oct 2011
    • 1

    How to include a button click procedure in an if then statement?

    Im writing an if then statement and i want it to say something like this:

    If intx = 1 and btn.click = true then
    'the rest of code
    end if

    But obviously "btn.click" isnt a real command. Any ideas?
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #2
    To start I don't think you can do this. click is an asynchronous event and your If statement is synchronous. What I'm really saying here is that any goal of the above code is invalid so I would ask you to explain what it is you want to do.
    If you wanted to know if a particular button had been clicked when this If statement runs, then that is easy. Simply create a global boolean flag such as

    bMyButtonWasCli cked

    In the button_click event set this value to TRUE and when your If Statement gets called it will be true only if the button event occurred. Be sure to set it to false inside your If code so it isn't just always true(unless thats what you want).

    The other way is to reverse the logic and put your if statement inside the button_click event. If the IF statement runs then you know that the button_click event was called.

    Code:
    Private Sub button1_Click(sender As System.Object, e As System.EventArgs) Handles button1.Click
        If intx = 1 then
         'the rest of code
        end if 
    
    End Sub

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Or you can use an STATE BUTTON and since the button is an object and its state is an attribute you can use it wherever you want.

      Comment

      Working...