Question Need Help with radio buttons

steveosh

Member
Joined
Dec 22, 2012
Messages
10
Programming Experience
Beginner
Hi all.

to be perfectly honest I am very very new with VB - I have learned some basics to create a program that does some math calculations.

What i like to do now is to continue on and create a program that has the following:

1) 5 different Group boxes that each has 5 to 8 radio buttons in each group.

2) there will be 2 input text boxes a user will enter .... ex. num1 and num2

What i'd like to do is see if it is possible to give each radio button a numerical value. for the follwing.

The user enters a value for num1 as 100 ... and a value for num2 as 12

In group box 1 clicks on the 2nd radio button ---- by choosing this button it will add 2% of (num1 + num2) (but if the 4th radio chosen then it would subtract 6% of (num1 + num2)

In group box 2 clicks on the 5th radio button ---- by choosing this button it will add 5% of (num1 + num2)
In group box 3 clicks on the 3rd radio button ---- by choosing this button it will add 6% of (num1 + num2)
In group box 4 clicks on the 1st radio button ---- by choosing this button it will add 3% of (num1 + num2)
In group box 5 clicks on the 2nd radio button ---- by choosing this button it will add 5% of (num1 + num2)


in a result label - I like the answer to be displayed based on the chosen radio buttons clicked.

I have the lay out already and double clicked a calculate button for coding BUT ??????

Is that possible.. Any help would greatly be appreciated.

I have a program for golf. A person will enter a num1 value ( Yards to Hole = num1) + (elevation = num2).. in the first group there are options Top spin - Top middle spin - center sping - bottom spin - back spin.... In the second group wind direction --- headwind - bottom right - bottomleft --- side wind - up - up right.. for example.

so a person enter Yards to Hole =100 elevation 4

so it would be reesultlabel = (num1 + num2) + (group1 - Backspin 5% of the sum of num1 + num2) + (group2 - Headwind 10% of the sum of num1 + num2) and so forth.....
 
Use a Select Case block, adapted to suit your own project:

Select Case True
Case radiobutton5.Checked
percent = 5
Case radiobutton3.Checked
percent = 6
Case radiobutton4.Checked
percent = 3
'etc
End Select
result = (num1 + num2) + ((num1 + num2) * (percent / 100)))
 
Last edited:
looks good just 1 more question please. i don't just want 5% ( i want 5% of the total of num1 and num2 added together) so what ever number is put in num1 and num2 will be different for each shot.
ie num1 = 189 num2= 5 .. so in this case i'd want resultLabel to show --- (num1 + num2) + (.05 * num1) in this case (189 + 5) + (.05 * 194) = 203.7.

Because i have 5 Different Groupboxes (each with between 4-8 different radio buttons in each group BUT only 1 radiobutton checked for each) each button that is checked has a different percentage i want added to the original num1 and num2 total.

here is a screen shot of what the design of the application.


design.jpg
 
So If a person picks the First SPIN radio button it would asubtract 5 yards to the (num1 + num2)

But if they picked the Last SPIN radiobutton it would add 10 yards to the (num1 + num2)

Group 2 Wind Direction if they picked UP -- it would subtract 4 yards but if they picked DOWN radiobutton it would add 15 Yards to the total thats displayed in resultLabel

etc
 
I gave you a small sample of the Select Case block using True as the control expression. You need to adapt it to work with your own program, adding the code you require after each case, including the formula and where the result should be output. You will need a separate Select Case block for each of your groupboxes. Also specify the groupbox control name along with the radiobutton's name. Example:
Case groupbox1.radiobutton1.Checked
Start with an initial value, and adjust it as each block of code is processed, in order.
 
Makes sense thank you... for now lol

I really appreciate it, i will try it in the morning.

Thank you so much,


I gave you a small sample of the Select Case block using True as the control expression. You need to adapt it to work with your own program, adding the code you require after each case, including the formula and where the result should be output. You will need a separate Select Case block for each of your groupboxes. Also specify the groupbox control name along with the radiobutton's name. Example:
Case groupbox1.radiobutton1.Checked
Start with an initial value, and adjust it as each block of code is processed, in order.
 
1 more question if i may.... can you place the radio buttons first on the page and then draw a group box around them? or do you have to draw the group box first and then add the radio buttons...

I added the Case groupbox1.radiobutton1.Checked

but it is underlined and say " 'spin1radiobutton' is not a member of 'System.Windows.Forms.GroupBox'.

Sorry like i said I have just started VB .. and trying to self teach.
 
Here what i got so far but the part thats bold has the line under it and it says 'spin1radiobutton' is not a member of 'System.Windows.Forms.GroupBox'. when my mouse moves over

Dim num1TextBox As Integer
Dim spin1b As Decimal
Dim resultA As Integer
Select Case True
Case spinGroupBox.spin1radiobutton.Checked
spin1b = (num1TextBox * 0.95)
Case spinGroupBox.spin2radiobutton.Checked
spin1b = (num1TextBox * 0.85)
Case spinGroupBox.spin3radiobutton4.Checked
spin1b = (num1TextBox * 0.8)
'etc
End Select
resultA = (num1TextBox) + (num2TextBox) + spin1b
 
Back
Top