View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Reset All Command Buttons on an Excel UserForm

Dim booCommandButton(1 to 80) as boolean

Private Sub CommandButton9_Click()
booCommandButton(9) = not boocommandbutton(9)

If booCommandButton(9) = true Then
CommandButton9.BackColor = &HFFFFFF
Else
CommandButton9.BackColor = &H808080
End If

Call StringBuilder

End Sub

Then in some buttonclick event:

Private Sub cBtnResetAllBooleans()
dim iCtr as long

for ictr = lbound(booCommandButton) to ubound(booCommandButton)
me.controls("commandbutton" & ictr).value = false
booCommandButton(ictr) = false
next ictr

End sub

(Untested, uncompiled.)

===========




wrote:

On 14 Jan, 19:46, Dave Peterson wrote:
If the boolean variable myBln is already false, then:
myBln = false
won't hurt a bit.

You could use:
if mybln = true then mybln = false

But I don't see much of an improvement.

======
Have you thought about using an array of booleans? Then you could loop through
the array.







wrote:

<<snipped

Dave,


You are correct in assuming that the buttons are boolean variables and
it would be easy to do as you say, however, not all of the 80 forms
have the same amount of buttons. Some have as many as 45. I also
only want to rest the ones which have been selected.


I am currently trying to adapt the code which Peter posted but it is
cycling all of the buttons (I should have made the fact that I only
want the selected buttons to be deselected earlier so apologies for
that).


I'd be extremely grateful if anyone could assist in some code to only
reset the 'active' buttons.


Once again many thanks.


Glen


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Dave,

I am fairly new to vba so I am not sure what you mean about using an
array of booleans. Could you clarify please?

Thanks,

Glen


--

Dave Peterson