|
-
Jun 20th, 2005, 12:23 AM
#1
Thread Starter
New Member
Solved - Toggle Button Code
I'm running VBA within MS Excel97 and like to know the code for the
following situation:
Form with ToggleButton, the button is labelled "1"
When I click the button, I'd like it to
a) become invisible (preferred), or
b) change it's label from "1" to "0"
On clicking the button again, i'd like to reverse he previous actions.
May sound to trivial for you to even bother about, but I have no previous
programming experience, and your reply would help me greatly with a
project I'm working on.
Thanks & Rgds, Andreas
Last edited by afehrmann; Jun 21st, 2005 at 06:27 AM.
Reason: Solved
-
Jun 20th, 2005, 01:06 AM
#2
Re: Toggle Button Code
it is very easy to make a button toggle somthing
Private Sub CommandButton1_Click()
CommandButton1.Visible = Not CommandButton1.Visible
End Sub
but of course this won't work, once it is not visible you can not click it again to bring it back, so it depends what else your code is doing, you my need to just set it back to visible later in the code
CommandButton1.Visible = true
pete
-
Jun 20th, 2005, 01:22 AM
#3
Thread Starter
New Member
Re: Toggle Button Code
Thanks for the quick reply. Works like a charm, but as you said, it works
onlly once: since it's invisible I can't toggle back and forth.
Is there a way to change the caption of the button from "1" to blank and
back to "1" with the next click?
Rgds, Andreas
(Adelaide, Australia...in case you're wondering where this dummy novice is from)
-
Jun 20th, 2005, 03:40 AM
#4
Re: Toggle Button Code
Private Sub CommandButton1_Click()
Static onoff As Boolean
onoff = Not onoff
CommandButton1.Caption = -CInt(onoff)
End Sub
pete
-
Jun 20th, 2005, 03:51 AM
#5
Re: Toggle Button Code
Code:
Private Sub tglButton_Click()
tblButton.Caption = iif(tglButton,"1","0")
End Sub
Or some thing like that. The true/flase part of the iif may need reversing...
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 20th, 2005, 04:38 AM
#6
Thread Starter
New Member
Re: Toggle Button Code
Thks Ecniv...
that routine only works once, not repeatedly...Rgds, Andreas
-
Jun 21st, 2005, 02:40 AM
#7
Re: Toggle Button Code
Uh? only once?
Should fire each time the toggle button is pressed.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 21st, 2005, 03:09 AM
#8
Re: Toggle Button Code
this fixes ecniv example
CommandButton1.Caption = IIf(CommandButton1.Caption = 0, "1", "0")
pete
-
Jun 21st, 2005, 03:35 AM
#9
Re: Toggle Button Code
Hmmm - but the tglButton should be true or false depending on whether it is pressed or not - shouldn't need to fix it... Oh btw you'd need the speechmarks around the 0 in the iif - 'cause it is text and not a number 
Edit:
Ok I have tested on a toggle button and works fine (original example).
There must be something else you've done if it is not working.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 21st, 2005, 04:13 AM
#10
Re: Toggle Button Code
works anyway, and the toggle button state is always the same when the button is pushed
pete
-
Jun 21st, 2005, 06:25 AM
#11
Thread Starter
New Member
Re: Toggle Button Code
Problem Solved.
Thks for your help...Rgds, Andreas
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
|