code for radiobutton and groupbox --- Problems getting errors when run

steveosh

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

I am not sure if this is a problem - or if i am on the right path or not even close. When i run the program it loads, I do not get any errors but i can NOT get the resultLabel to show the addition Math or answer
the code below: (its not really HTML code....

I am using Visual Basic Express 2008

HTML:
'Declares Local Variables
        Dim num1Decimal As Decimal
        Dim num2Decimal As Decimal
        Dim resultLabel As Decimal

        'Place the Data in the Variables
        num1Decimal = Val(num1.Text)
        num2Decimal = Val(num1.Text)

        'This is the information from the radiobuttons
        ' Create and initialize a GroupBox and a Button control.
        Dim spinGroupBox As New GroupBox
        Dim resultADecimal As Decimal
        Dim spin1b As Decimal
        Select Case True
            Case spin1RadioButton.Checked
                spin1b = 0.095
            Case spin2RadioButton.Checked
                spin1b = 0.085
            Case spin3RadioButton.Checked
                spin1b = 0.08
            Case spin4RadioButton.Checked
                spin1b = 0.08
            Case spin5RadioButton.Checked
                spin1b = 0.08
        End Select
        resultADecimal = spin1b

        ' Create and initialize a GroupBox and a Button control. 
        Dim windGroupBox As New GroupBox
        Dim wind1b As Decimal
        Dim resultBDecimal As Decimal
        Select Case True
            Case upRadioButton.Checked
                wind1b = 0.095
            Case ULRadioButton.Checked
                wind1b = 0.085
            Case urRadioButton.Checked
                wind1b = 0.075
            Case downRadioButton.Checked
                wind1b = 0.07
            Case dlRadioButton.Checked
                wind1b = 0.065
            Case drRadioButton.Checked
                wind1b = 0.06
            Case leftRadioButton.Checked
                wind1b = 0.055
            Case rightRadioButton.Checked
                wind1b = 0.05

        End Select
        resultBDecimal = wind1b

        ' Create and initialize a GroupBox and a Button control. 
        Dim locationGroupBox As New GroupBox
        Dim location1b As Decimal
        Dim resultCDecimal As Decimal
        Select Case True
            Case fairwayRadioButton.Checked
                location1b = 0.095
            Case firstCutRadioButton.Checked
                location1b = 0.085
            Case secondCutRadioButton.Checked
                location1b = 0.075
            Case deepRadioButton.Checked
                location1b = 0.07
            Case sandRadioButton.Checked
                location1b = 0.065
            Case weedsRadioButton.Checked
                location1b = 0.06
            Case mulchRadioButton.Checked
                location1b = 0.055

        End Select
        resultCDecimal = location1b

        ' Create and initialize a GroupBox and a Button control. 
        Dim swingGroupBox As New GroupBox
        Dim swing1b As Decimal
        Dim resultDDecimal As Decimal
        Select Case True
            Case fullRadioButton.Checked
                swing1b = 0.095
            Case pitchRadioButton.Checked
                swing1b = 0.085
            Case chipRadioButton.Checked
                swing1b = 0.075
            Case flopRadioButton.Checked
                swing1b = 0.07
            Case punchRadioButton.Checked
                swing1b = 0.065

        End Select
        resultDDecimal = swing1b

        ' Create and initialize a GroupBox and a Button control. 
        Dim lieGroupBox As New GroupBox
        Dim lie1b As Decimal
        Dim resultEDecimal As Decimal
        Select Case True
            Case lie1RadioButton.Checked
                lie1b = 0.095
            Case lie2RadioButton.Checked
                lie1b = 0.085
            Case lie3RadioButton.Checked
                lie1b = 0.075
            Case lie4RadioButton.Checked
                lie1b = 0.07
            Case lie5RadioButton.Checked
                lie1b = 0.065
            Case lie6RadioButton.Checked
                lie1b = 0.06
            Case lie7RadioButton.Checked
                lie1b = 0.055
            Case lie8RadioButton.Checked
                lie1b = 0.05

        End Select
        resultEDecimal = lie1b

        ' Calculate and Display the Yards to Hole needed.
        resultLabel = num1Decimal + (num1Decimal * resultADecimal) + (num2Decimal * resultBDecimal) + (num1Decimal * resultCDecimal) + (num1Decimal * resultDDecimal) + (num1Decimal * resultEDecimal)
 
You seem to be under some misconceptions about what a Decimal variable can do. The comment on that last line of code says:
' Calculate and Display the Yards to Hole needed.
I see the calculation and you're assigning the result to that 'resultLabel' variable, but there's no display going on. All you're doing is storing a number. The fact that you use 'Label' in the variable name doesn't magically make it visible to the user. If you want to display something to the user then you need to use a control. In this case, that would logically be a Label control. You can then assign the result of your calculation to its Text property.
 
;that make sense but

That would make sense

I am sorry I really am new to this, been trying programming for 3-4 days now.

I understand that it is stored, what would i need to type to get it displayed

Please


You seem to be under some misconceptions about what a Decimal variable can do. The comment on that last line of code says:I see the calculation and you're assigning the result to that 'resultLabel' variable, but there's no display going on. All you're doing is storing a number. The fact that you use 'Label' in the variable name doesn't magically make it visible to the user. If you want to display something to the user then you need to use a control. In this case, that would logically be a Label control. You can then assign the result of your calculation to its Text property.
 
someone suggested ---- resultLabel.Text = (num1Decimal + (num1Decimal * resultADecimal) + (num2Decimal * resultBDecimal) + (num1Decimal * resultCDecimal) + (num1Decimal * resultDDecimal) + (num1Decimal * resultEDecimal)).ToString

BUT now i get 'Text" is not a member of 'Decimal'
 
Hi,

You are misinterpreting what you are being told by your various sources and jcmilhinney.

You have declared a variable called resultLabel of type Decimal in your code but you have missed jcmilhinney's point that this is NOT a control on a form and therefore there is no way to display the result. You have then been given advice from someone to use the Text property of a Label to display the result. You have then interpreted this to mean that you can set resultLabel.Text to display the result but this in incorrect since your Decimal variable is not a Label.

This is where declaring your variables and controls with meaningful names becomes so important so that they immediately remind you what type of variable or control you are dealing with.

To fix your problem try the following:-

1) Change the name of your current resultLabel variable to something like:-

VB.NET:
Dim decNumberOfYardsToHole as Decimal

Then change your final calculation to say:-

VB.NET:
decNumberOfYardsToHole = num1Decimal + (num1Decimal * resultADecimal) + (num2Decimal * resultBDecimal) + (num1Decimal * resultCDecimal) + (num1Decimal * resultDDecimal) + (num1Decimal * resultEDecimal)

This is now a lot more readable and as you can see you now have a variable called decNumberOfYardsToHole with the result of your calculation.

2) Now, move your focus to the form and from the tool box drag a Label control onto the form. In the properties window (F4) change the name of this control to resultLabel. You now have a TRUE label called resultLabel which does have a .Text property.

3) Move back to the code and AFTER the calculation of decNumberOfYardsToHole add this to the code:-

VB.NET:
resultLabel.Text = decNumberOfYardsToHole.ToString

Now when you run the project you will see that your calculation is now displayed as you are expecting.

Hope that helps and Merry Christmas.

Cheers,

Ian
 
Back
Top