Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > option button change in an array


Reply
 
Thread Tools Display Modes
  #1  
Old 03-02-2006, 07:37 PM
IrishBoyX IrishBoyX is offline
Newcomer
 
Join Date: Mar 2004
Posts: 5
Default option button change in an array


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

Code:
'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
Reply With Quote
  #2  
Old 03-03-2006, 04:54 AM
Timbo's Avatar
Timbo Timbo is offline
Green-Eyed

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Bangkok, Thailand
Posts: 10,261
Default

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
__________________
"He's not the Messiah. He's a very naughty boy!" - Brian's mum

Can't find the answer? >> Try something new!
Become a Professional
Reply With Quote
  #3  
Old 03-03-2006, 05:08 AM
IrishBoyX IrishBoyX is offline
Newcomer
 
Join Date: Mar 2004
Posts: 5
Default

apologies, looking at it with morning eyes i got it

i used the .enabled property instead of .value

apologies, fine now
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->