option button change in an array

IrishBoyX
03-02-2006, 07:37 PM
I have a userform with 10 grouped option buttons. I want to be able to click one of them and it deducts a number from a number in a cell (b3:k3) depending on which button A 2 3 4... 10

this part functions correctly

if i click on another button it should add one back onto the deselected button and add one onto the selected button, it runs through the opb1_change sub twice

the first time it detects the deselected buttons caption name but always comes back with the button being enabled.

the second time it works correctly (deducting one from the new button enabled)

Any Ideas



'this is in class1

Private WithEvents opb1 As MSForms.OptionButton
Dim X As Integer
Dim AddMinus As Integer

Sub SetOptionButton(ByVal opb As MSForms.OptionButton)
Set opb1 = opb
End Sub

Private Sub opb1_change()
If Right(opb1.Caption, 1) <> "A" Then X = opb1.Caption Else: X = 1
If opb1.Enabled = False Then AddMinus = -1 : else AddMinus = 1
End Sub

Sub Main()
Range("a3").Offset(0, X).Value = Range("a3").Offset(0, X).Value - 1*AddMinus
Call AdjustCount
End Sub

Sub AdjustCount()
Select Case X ' red seven
Case "1": Range("l30").Value = Range("l30").Value - 1 * AddMinus
Case "2": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "3": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "4": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "5": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "6": Range("l30").Value = Range("l30").Value + 1 * AddMinus
Case "7": Range("l30").Value = Range("l30").Value + 1 / 2 * AddMinus
Case "8": Range("l30").Value = Range("l30").Value
Case "9": Range("l30").Value = Range("l30").Value
Case "10": Range("l30").Value = Range("l30").Value - 1 * AddMinus
End Select
End Sub

'this is in userform1

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 c(i)
Set c(i) = New Class1
c(i).SetOptionButton obj
obj.Tag = i
End If
Next

End Sub

Timbo
03-03-2006, 04:54 AM
Have you put a break point in your routine to see what is going on? I have a suspicion that the 'Change' event is cascading ;)

IrishBoyX
03-03-2006, 05:08 AM
apologies, looking at it with morning eyes i got it

i used the .enabled property instead of .value

apologies, fine now

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum