Q: Calculate the pressed optionbuttons
I have a form with 4 option buttons and a command button. I am using this code so far: Dim Option1 Dim Option2 Dim Option3 Dim Option4 Dim EndResult Option1 = 5 Option2 = 1 Option3 = 5 Option4 = 1 How can I make the code so when command button is pressed it will only calculate the option buttons that have been pressed?
A: Sometimes I can't see the purpose of an application but oke that's not my problem. What you must do I check in the Click event of the command button which option buttons are true and then calcaulate the result. Just give the optionbox the right value as the caption. This way you don't have to use the four variabeles option1 to option4. Private Sub Command1_Click() Dim EndResult% EndResult = 0 If Option1.Value Then EndResult = CInt(Option1.Caption) If Option2.Value Then EndResult = CInt(Option2.Caption) If Option3.Value Then EndResult = CInt(Option3.Caption) If Option4.Value Then EndResult = CInt(Option4.Caption) MsgBox Str(EndResult) End Sub Return