Option Group Vb problem

J

Jon

Greeting,
I have option Group frame has 4 option buttons to show the status of student
and I have 1 text box to show student total marks. What I want to do is when
the text box has the value between 100 and 89.5 the option button #1 will be
selected and could not be edited until the value changed. Button 2 selected
if the value is between 89.4 and 75. Button3 selected if value is between
74.4 and 60 and less than 60 button 4 will be selected.

Any help please?
 
O

OssieMac

Insert the following code in the After Update event of the text box and set
the properties of the Frame to Locked (See data tab in properties). The
buttons will only change when the textbox is changed.

Edit the code to suit your textbox name and frame name. You may also want to
edit the Case values. Note: Upper and lower values not required in the Case
statements. The code processes the first true statement only.

Private Sub Text0_AfterUpdate()
Select Case Me.Text0
Case Is > 89.4
Me.Frame4 = 1
Case Is > 75
Me.Frame4 = 2
Case Is > 60
Me.Frame4 = 3
Case Is < 60
Me.Frame4 = 4
Case Else

End Select

End Sub
 
O

OssieMac

You might find the following code better. It dempnstrates the >= when used in
case statements. Bit different to the way it is done elsewhere in code.

Private Sub Text0_AfterUpdate()
Select Case Me.Text0
Case 89.5, Is > 89.5 '=> 89.5
Me.Frame4 = 1
Case 75, Is > 75 '=> 75
Me.Frame4 = 2
Case 60, Is > 60 '=> 60
Me.Frame4 = 3
Case Is < 60 '< 60
Me.Frame4 = 4
End Select
End Sub
 
J

Jon

Thank you OssieMac
but if the value is >60 the selected button is 1 not 3!!! please adivse?
 
O

OssieMac

Hi Jon,

Have a look at the properties for each of the option buttons. In design
view, select each option button in turn and then on the properties Data tab
check that the Option Value is what you expect for the particular button. You
can change the values to suit.

Also the case statements must start at the highest value (> 89.5) and reduce
in the correct order.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top