Broblem with Option Button

Started by Marty Francom, December 24, 2006, 03:16:55 PM

Previous topic - Next topic

Marty Francom

I have one group of option buttons on one form.   When I click on the option button to change the option.  I want to have that trigger the painting of a listbox.   What seems to be happening is when I click on the option button.  The program fires the code in each of the option buttons and I get the same result in the list box regardless of which option button is clicked. The code in Option1_BN_Clicked is always the last code to fire.    What am I doing wrong?   Is there a simple sample program that shows how to use the Option buttons?
.
This the code where the problem is located:

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_OPTION1_BN_CLICKED ( _
                                 ControlIndex     As Long,  _  ' index in Control Array
                                 hWndForm         As Dword, _  ' handle of Form
                                 hWndControl      As Dword, _  ' handle of Control
                                 idButtonControl  As Long   _  ' identifier of button
                                 ) As Long    
 
  optn = 1
  Call PaintList2(optn)

End Function


'------------------------------------------------------------------------------------------------------------------------
Function FORM1_OPTION2_BN_CLICKED ( _
                                 ControlIndex     As Long,  _  ' index in Control Array
                                 hWndForm         As Dword, _  ' handle of Form
                                 hWndControl      As Dword, _  ' handle of Control
                                 idButtonControl  As Long   _  ' identifier of button
                                 ) As Long                                        
                                 
  optn = 2
  Call PaintList2(optn)
   
End Function


'------------------------------------------------------------------------------------------------------------------------
Function FORM1_OPTION3_BN_CLICKED ( _
                                 ControlIndex     As Long,  _  ' index in Control Array
                                 hWndForm         As Dword, _  ' handle of Form
                                 hWndControl      As Dword, _  ' handle of Control
                                 idButtonControl  As Long   _  ' identifier of button
                                 ) As Long

  optn = 3
  Call PaintList2(optn)

End Function


Elias Montoya

I was getting the same results before Paul fixed Firefly, clicking
1 option button checked them all in the group.

Did you download the fix that paul made?


http://www.planetsquires.com/forums/viewtopic.php?t=2181

Marty Francom

My problem is not that all three options get the bullet.  That seems to work OK. That is click one option button and it gets the bullet and the bullet is removed from the others.
.
The problem is the code in the "Function FORM1_OPTIONx_BN_CLICKED " for ALL the functions gets fired when you click just one option button.
.
I am using FFengine dated 11/20/2006

David Kenny

Marty,

I would delete the second two option buttons, right-click on the one that is left and select copy.  Now right-click again and select paste.  Say yes when it asks if you want to create a control array.  Paste again and move the two controls where you would like them.

Delete the two extra BN_CLICKED routines.

Change your two lines:
  optn = 1
  Call PaintList2(optn)

To:

   Call PaintList2(ControlIndex+1) ' add one becase the index is zero based

Control arrays are a nice feature.  Check out the Handles and ControlId's dialog to see how you can access the arrays that hold the handles and ID's for the three option buttons.

Marty Francom

Thanks for the tip I will give that a try & see if that fixes my problem

TechSupport

Quote from: Marty FrancomThe problem is the code in the "Function FORM1_OPTIONx_BN_CLICKED " for ALL the functions gets fired when you click just one option button.

Yes, there seems to have been a bug creep in there somewhere.... I will fix as soon as possible.

TechSupport

Correction: This is not really a "bug" as such. I double checked the generated code and the Control ID's are all the same for the Option Buttons in the group. This is because when the Option Button is created, the "Index" property is set to "1" for each new button in the group. If you change the Index properties to consecutive values then the ControlID's are generated with different values and you won't have the multiple firing of the BN_CLICKED message.

Marty Francom

Thanks Paul...
I will give that a try....

David Kenny

I was not proposing a solution to the problem you were experiencing.  I hope my post didn't come across as "this is what you did wrong", but rather a way to reduce code by using the same routine to process all three buttons. It might not be the way to go in all applications, but I noticed that it would work really slick in this particular example.

It still would have solved the problem, but only because FF adjusts the ControlIindex for each control in the array automatically as you create them.  The Index is still set to 1 for each.  Not sure what the difference is between those two in FF… Maybe Paul can explain  :wink: