By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,558 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,558 IT Pros & Developers. It's quick & easy.

Button and If Statement

P: 63
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
...
Dec 5 '07 #1
Share this Question
Share on Google+
10 Replies


100+
P: 284
i donot think you can use
Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1.  if checkbox.value=false then
which is now become equal to
Expand|Select|Wrap|Line Numbers
  1. If cmdButton_Click = False Then
i think you understand



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
...
Dec 5 '07 #2

lee123
100+
P: 556
but whats the rest of the code this is an IF statement is there a false to this? like:

Expand|Select|Wrap|Line Numbers
  1. If checkbox.value = false then
  2.   ' do something?
  3. else
  4.  ' Not do something?
  5.  
  6. End IF
lee123
Dec 5 '07 #3

100+
P: 284
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


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

Expand|Select|Wrap|Line Numbers
  1. If checkbox.value = false then
  2. ' do something?
  3. else
  4. ' Not do something?
  5.  
  6. End IF
lee123
Dec 6 '07 #4

Dököll
Expert 100+
P: 2,364
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!

Expand|Select|Wrap|Line Numbers
  1.  
  2. .Enabled may also work for you
  3.  
  4. Private Sub...
  5.  
  6. If cmdMyButton.Enabled = False Then
  7. MsgBox ("Hey, what gives!")
  8. Else
  9. MsgBox  ("That's what I am talking about!")
  10. End If
  11.  
  12.  
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
Dec 6 '07 #5

lee123
100+
P: 556
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
Dec 6 '07 #6

debasisdas
Expert 5K+
P: 8,127
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.
Dec 7 '07 #7

vdraceil
100+
P: 236
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).
Dec 9 '07 #8

9815402440
100+
P: 180
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(index 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
Dec 9 '07 #9

P: 41
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...

Expand|Select|Wrap|Line Numbers
  1. If Check1.Value = 0 Then
  2.    ' Do Something
  3. Else
  4.    ' Do Something Else
  5. End If
Torgg
Dec 11 '07 #10

jamesd0142
100+
P: 469
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)
Dec 11 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.