Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Change event

I have a UserForm with four frames; each frame groups 5 OptionButtons and a
fifth frame has 6 OptionButtons.
Everytime a user clicks on one of the OptionButtons, I'd like a value to be
updated in a TextBox (depending on which OptionButton is clicked).
OptionButton1 adds 1 to the Textbox, OptionButton2 adds 2, etc. I know I
can do this using a Sub OptionButton1_Change() procedure (creating 26
procedures) but is there a more efficient way to do it?
Thanks.
Bert

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change event


Bert;164588 Wrote:
I have a UserForm with four frames; each frame groups 5 OptionButtons
and a
fifth frame has 6 OptionButtons.
Everytime a user clicks on one of the OptionButtons, I'd like a value
to be
updated in a TextBox (depending on which OptionButton is clicked).
OptionButton1 adds 1 to the Textbox, OptionButton2 adds 2, etc. I know
I
can do this using a Sub OptionButton1_Change() procedure (creating 26
procedures) but is there a more efficient way to do it?
Thanks.
Bert


Hello Bert,

There would have been if Microsoft had provided Control Arrays like
Visual Basic does. There are ways to simulate this, but I think all the
extra code needed to provide this type of functionality out weighs its
benefits.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=45680

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Change event

Thanks, Leith.
I appreciate you insights. (I guess they were figuring cut-and-paste is
just as good. I was hoping though...)
At any rate, thanks for your response.
Bert

"Leith Ross" wrote in message
...

Bert;164588 Wrote:
I have a UserForm with four frames; each frame groups 5 OptionButtons
and a
fifth frame has 6 OptionButtons.
Everytime a user clicks on one of the OptionButtons, I'd like a value
to be
updated in a TextBox (depending on which OptionButton is clicked).
OptionButton1 adds 1 to the Textbox, OptionButton2 adds 2, etc. I know
I
can do this using a Sub OptionButton1_Change() procedure (creating 26
procedures) but is there a more efficient way to do it?
Thanks.
Bert


Hello Bert,

There would have been if Microsoft had provided Control Arrays like
Visual Basic does. There are ways to simulate this, but I think all the
extra code needed to provide this type of functionality out weighs its
benefits.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:
http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=45680


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Change event

As Leith said, doing it is a bit more effort than it may be worth.

Here is one way using the Click event rather than a Change event in a Class.

1. Create your UserForm1 with the option buttons and TextBox1.
2. Add a class and use this code. Name the class in the project explorer as
cOptionButtons.

Private WithEvents obttn1 As MSForms.OptionButton

Sub SendOptionButton(ByVal obttn As MSForms.OptionButton)
Set obttn1 = obttn
End Sub

Private Sub obttn1_Click()
If obttn1.Value = True Then IncrementTB1 obttn1
End Sub

3. Add a Module with this code.

Sub IncrementTB1(ob As MSForms.OptionButton)
If UserForm1.TextBox1.Value = "" Then UserForm1.TextBox1.Value = "0"
UserForm1.TextBox1.Value = CStr(CDbl(UserForm1.TextBox1.Value) +
CDbl(ob.Tag))
End Sub

4. Add this code to UserForm1. The use of the Tag property makes this a bit
easier.

Dim ob() As cOptionButtons

Private Sub UserForm_Initialize()
Dim obj As MSForms.Control, i As Long

For Each obj In Me.Controls
If TypeName(obj) = "OptionButton" Then
i = i + 1
ReDim Preserve ob(i)
Set ob(i) = New cOptionButtons
ob(i).SendOptionButton obj
obj.Tag = i
End If
Next
End Sub

Private Sub CommandButton1_Click()
MsgBox TextBox1.Value
Unload Me
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Change event

Thanks, Kenneth.
I've taken the simpler route of creating a procedure to trap changes to each
OptionButton; however, I'm going to hold onto to your code and will include
it as I refine my "solution." Thanks for your help; I appreciate it!
Bert.



"Kenneth Hobson" wrote in message
...
As Leith said, doing it is a bit more effort than it may be worth.

Here is one way using the Click event rather than a Change event in a
Class.

1. Create your UserForm1 with the option buttons and TextBox1.
2. Add a class and use this code. Name the class in the project explorer
as cOptionButtons.

Private WithEvents obttn1 As MSForms.OptionButton

Sub SendOptionButton(ByVal obttn As MSForms.OptionButton)
Set obttn1 = obttn
End Sub

Private Sub obttn1_Click()
If obttn1.Value = True Then IncrementTB1 obttn1
End Sub

3. Add a Module with this code.

Sub IncrementTB1(ob As MSForms.OptionButton)
If UserForm1.TextBox1.Value = "" Then UserForm1.TextBox1.Value = "0"
UserForm1.TextBox1.Value = CStr(CDbl(UserForm1.TextBox1.Value) +
CDbl(ob.Tag))
End Sub

4. Add this code to UserForm1. The use of the Tag property makes this a
bit easier.

Dim ob() As cOptionButtons

Private Sub UserForm_Initialize()
Dim obj As MSForms.Control, i As Long

For Each obj In Me.Controls
If TypeName(obj) = "OptionButton" Then
i = i + 1
ReDim Preserve ob(i)
Set ob(i) = New cOptionButtons
ob(i).SendOptionButton obj
obj.Tag = i
End If
Next
End Sub

Private Sub CommandButton1_Click()
MsgBox TextBox1.Value
Unload Me
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
apply cell change event to single column - WorksheetChange Event [email protected] Excel Programming 6 May 4th 08 02:28 AM
How do I change a Worksheet_change event to a beforesave event? Tueanker Excel Programming 5 June 29th 07 03:00 PM
MsgBox in Enter event causes combobox not to run Change event Richard Excel Programming 0 March 6th 06 02:52 PM
Change event and calculate event Antje Excel Programming 1 March 29th 05 09:03 PM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"