Button and If Statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    Button and If Statement

    How can I write an if -statement where a condition is made true when a button is not clicked?

    i.e. If cmdButton_Click = False Then
    ...
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    #2
    i donot think you can use
    Code:
    If cmdButton_Click = False Then
    but this task can be achived in ohther way
    make a check box
    by default it is unchecke (false)
    and when button is clicked give its value ture
    now use condintion
    Code:
     if checkbox.value=false then
    which is now become equal to
    Code:
    If cmdButton_Click = False Then
    i think you understand



    Originally posted by MiziaQ
    How can I write an if -statement where a condition is made true when a button is not clicked?

    i.e. If cmdButton_Click = False Then
    ...

    Comment

    • lee123
      Contributor
      • Feb 2007
      • 556

      #3
      but whats the rest of the code this is an IF statement is there a false to this? like:

      Code:
      If checkbox.value = false then
        ' do something?
      else
       ' Not do something?
      
      End IF
      lee123

      Comment

      • muddasirmunir
        Contributor
        • Jan 2007
        • 284

        #4
        plz clarify , i did not understand what did you mean by
        "what is the rest of the code"

        if you explian what you actually want to do may be we can help
        you better


        Originally posted by lee123
        but whats the rest of the code this is an IF statement is there a false to this? like:

        Code:
        If checkbox.value = false then
        ' do something?
        else
        ' Not do something?
         
        End IF
        lee123

        Comment

        • Dököll
          Recognized Expert Top Contributor
          • Nov 2006
          • 2379

          #5
          Originally posted by muddasirmunir
          plz clarify , i did not understand what did you mean by
          "what is the rest of the code"

          if you explian what you actually want to do may be we can help
          you better
          Hello, muddasirmunir!

          [CODE=VB]

          .Enabled may also work for you

          Private Sub...

          If cmdMyButton.Ena bled = False Then
          MsgBox ("Hey, what gives!")
          Else
          MsgBox ("That's what I am talking about!")
          End If

          [/CODE]

          MsgBox can be reoplaced by what you need, I believe previous OP attempted to relay similar info

          Open up another form rather than "MsgBox ("That's what I am talking about!")"

          Have fun!

          Dököll

          Comment

          • lee123
            Contributor
            • Feb 2007
            • 556

            #6
            yea i was responding to MIZIAQ question usually there is more to an if statement:

            example:

            they would want a checkbox to do something or a textbox to do something but this " if statement " doesn't have any of them

            lee123

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              The best thing to do is to use a checkbox instead of a command button and change its style. so it behaves like a toggle button. Then you need to use the value property.

              Comment

              • vdraceil
                New Member
                • Jul 2007
                • 236

                #8
                Write the code of IF CLICKED CONDITION under command buttons click event(this event is triggered immediately when the botton is clicked) and write the ELSE CONDITION under forms mousemove event(when the mouse pointer is over the form there is no chance for the button getting clicked).

                Comment

                • 9815402440
                  New Member
                  • Oct 2007
                  • 180

                  #9
                  hi
                  if i am not wrong then you are trying to know whether a button has been clicked or not ( from a group of buttons). if no button has been clicked then you want to do something. if this is the case then you have two ways out. first is to use index array. in this case single click event will occur for all buttons,
                  e.g.

                  private sub command_click(i ndex as integer)
                  'set value of variable here. and then chek the value in some other place to process.
                  end sub

                  other ways is declare a booleean vaiable at form level. in the form_load event (or anywhere you deem fit.) set it to false. set its value in the click event of each button to true. if the its value is false then no button is clicked.

                  hope i have not mis-interprated your question

                  regards
                  manpreet singh dhillon hoshiarpur

                  Comment

                  • Torgg
                    New Member
                    • Dec 2007
                    • 41

                    #10
                    MiziaQ

                    I think debasisdas has the best advice. Use a checkbox and change the "Style" property to graphical, this will make the checkbox appear to be a button. Then use the value property of the checkbox to see if it has been clicked. Like so...

                    [CODE=vb]If Check1.Value = 0 Then
                    ' Do Something
                    Else
                    ' Do Something Else
                    End If[/CODE]

                    Torgg
                    Last edited by Killer42; Dec 12 '07, 06:05 AM.

                    Comment

                    • jamesd0142
                      Contributor
                      • Sep 2007
                      • 471

                      #11
                      Apologies if this is repeating something above, I couldn't be bothered to read it all...

                      Why not say :

                      dim a as string = "0"

                      then a = "1" in the button.

                      So you can now say:
                      if a = 1 then... (it's been pressed)
                      else
                      .........(it hasn't been pressed)
                      Last edited by Killer42; Dec 11 '07, 10:14 PM.

                      Comment

                      Working...