I'm new in VB programming I did wrote this code so far but for some reason the senior does not calculate. Any help will greatly appreciate. This is what I'm trying to accomplished.
"basic monthly cost of a membership is $100 for adults and $75 for seniors. Members must choose a level of membership { Gold, which adds $300 to the cost of the membership; Silver, which adds $250 to the cost; or Bronze, which adds $150."

Public Class frmMembership

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        ' Names

        ' radAdult
        ' radSenior
        ' radGold
        ' radSilver
        ' radBronze
        ' btnCalculate
        ' txtMthFee

        ' Variables
        Dim fee As Double
        Dim adult As Double
        Dim senior As Double

        ' input from the membership
        'adult = CDbl(radAdult.Text) ' Monthly Cost
        'senior = CDbl(radSenior.Text) ' Monthly Cost
        'radAdult.Text = CStr(fee)
        fee = CDbl(fee)

        ' Calculate 
        ' fee = (txtMthFee.Text)

        ' Function
        If radAdult.Checked Then
            adult = 100
        ElseIf radSenior.Checked Then
            senior = 75
        End If

        ' add Monthly Membership
        If radGold.Checked Then
            fee = adult + 300
        ElseIf radSilver.Checked Then
            fee = adult + 250
        ElseIf radBronze.Checked Then
            fee = adult + 150
        ElseIf radSenior.Checked Then
            fee = senior + 300
        ElseIf radSenior.Checked Then
            fee = senior + 250
        ElseIf radSenior.Checked Then
            fee = senior + 150
        End If

        ' Display output
        txtMthFee.Text = CStr(fee)

    End Sub
End Class

I think u had done it wrong in here

' add Monthly Membership
        If radGold.Checked Then
            fee = adult + 300
        ElseIf radSilver.Checked Then
            fee = adult + 250
        ElseIf radBronze.Checked Then
            fee = adult + 150
        ElseIf radSenior.Checked Then
            fee = senior + 300
        ElseIf radSenior.Checked Then
            fee = senior + 250
        ElseIf radSenior.Checked Then
            fee = senior + 150
        End If

Why the radSenior.Checked had been repeated for several time?

Edited 5 Years Ago by BlurrieBlue: Coding alignment

Because,

adult and senior needs to choose membership. Gold, which adds $300 to the cost of the membership; Silver, which adds $250 to the cost; or Bronze, which adds $150."

I think u had done it wrong in here

' add Monthly Membership
        If radGold.Checked Then
            fee = adult + 300
        ElseIf radSilver.Checked Then
            fee = adult + 250
        ElseIf radBronze.Checked Then
            fee = adult + 150
        ElseIf radSenior.Checked Then
            fee = senior + 300
        ElseIf radSenior.Checked Then
            fee = senior + 250
        ElseIf radSenior.Checked Then
            fee = senior + 150
        End If

Why the radSenior.Checked had been repeated for several time?

Ya.. I know.. but your last three conditions shouldn't it be

ElseIf radGold.Checked Then
            fee = senior + 300
        ElseIf radSilver.Checked Then
            fee = senior + 250
        ElseIf radBronze.Checked Then
            fee = senior + 150

Or you can add the condition right after you had checked either adult or senior button had been checked, like

If radAdult.Checked Then
            adult = 100

         'your membership condition here

        ElseIf radSenior.Checked Then
            senior = 75
        End If

That is just my suggestion on how I will do it.

Ya.. I know.. but your last three conditions shouldn't it be

ElseIf radGold.Checked Then
            fee = senior + 300
        ElseIf radSilver.Checked Then
            fee = senior + 250
        ElseIf radBronze.Checked Then
            fee = senior + 150

Or you can add the condition right after you had checked either adult or senior button had been checked, like

If radAdult.Checked Then
            adult = 100

         'your membership condition here

        ElseIf radSenior.Checked Then
            senior = 75
        End If

That is just my suggestion on how I will do it.

Hi BlurrieBlue,
I did some change on to my code and I now the adult membership is not calculating.
would you please help and guide me what I'm doing wrong.
Thanks

' Variables
        Dim fee As Double
        Dim adult As Double
        Dim senior As Double

        If radAdult.Checked Then
            adult = 100
        ElseIf radSenior.Checked Then
            senior = 75
        End If

        ' add Monthly Membership
        ' Adult
        If radGold.Checked Then
            fee = adult + 300
        ElseIf radSilver.Checked Then
            fee = adult + 250
        ElseIf radBronze.Checked Then
            fee = adult + 150
        End If

        ' add Monthly Membership
        ' Senior

        If radGold.Checked = True Then
            fee = senior + 300
        ElseIf radSilver.Checked = True Then
            fee = senior + 250
        ElseIf radBronze.Checked = True Then
            fee = senior + 150
        End If

        ' Display output
        txtMthFee.Text = CStr(fee)

Hi, you may try it like this.

If radAdult.Checked = True Then
            adult = 100
            If radGold.Checked = True Then
                fee = adult + 300
            End If
            If radSilver.Checked = True Then
                fee = adult + 250
            End If
            If radBronze.Checked = True Then
                fee = adult + 150
            End If
        End If

        If radSenior.Checked = True Then
            senior = 75
            If radGold.Checked = True Then
                fee = senior + 300
            End If
            If radSilver.Checked = True Then
                fee = senior + 250
            End If
            If radBronze.Checked = True Then
                fee = senior + 150
            End If
        End If

        txtMthFee.Text = CStr(fee)

First of all the basic cost doesn't change, so it doesn't have to be in an if statement.
What needs to go in that if statement is if you are adding the adult or the senior cost to the membership.

I'm assuming that this is an exercise for IFs, so I'm not using select case.

' Variables
        Dim fee As Double
        Dim basic_fee as Double
        Dim membership_cost As Double

        If radAdult.Checked Then
            basic_fee = 100
        ElseIf radSenior.Checked Then
            basic_fee = 75
        Else txtMthFee.Text = "Please select your subscription category" 'Change this to whatever you want, but unless you've set one of the 2 as selected by default you need it. If you've set a default then you don't need 2 IFs, but only 1 as there is only 1 alternative
        exit sub 'So that the txtMthFee won't display the wrong number
        End If

        ' Monthly Membership

        If radGold.Checked Then
            membership_cost = 300
        ElseIf radSilver.Checked Then
            membership_cost = 250
        ElseIf radBronze.Checked Then
            membership_cost = 150
        Else txtMthFee.Text = "Please select your membership level" 'Change this to whatever you want, but unless you've set a default you need it. 
        exit sub 'So that the txtMthFee won't display the wrong number
        End If

fee = basic_fee + membership_cost

        ' Display output
        txtMthFee.Text = CStr(fee)

Edited 5 Years Ago by adam_k: n/a

First of all the basic cost doesn't change, so it doesn't have to be in an if statement.
What needs to go in that if statement is if you are adding the adult or the senior cost to the membership.

I'm assuming that this is an exercise for IFs, so I'm not using select case.

' Variables
        Dim fee As Double
        Dim basic_fee as Double
        Dim membership_cost As Double

        If radAdult.Checked Then
            basic_fee = 100
        ElseIf radSenior.Checked Then
            basic_fee = 75
        Else txtMthFee.Text = "Please select your subscription category" 'Change this to whatever you want, but unless you've set one of the 2 as selected by default you need it. If you've set a default then you don't need 2 IFs, but only 1 as there is only 1 alternative
        exit sub 'So that the txtMthFee won't display the wrong number
        End If

        ' Monthly Membership

        If radGold.Checked Then
            membership_cost = 300
        ElseIf radSilver.Checked Then
            membership_cost = 250
        ElseIf radBronze.Checked Then
            membership_cost = 150
        Else txtMthFee.Text = "Please select your membership level" 'Change this to whatever you want, but unless you've set a default you need it. 
        exit sub 'So that the txtMthFee won't display the wrong number
        End If

fee = basic_fee + membership_cost

        ' Display output
        txtMthFee.Text = CStr(fee)

Hey adam_k,

Thank you very much for you input in my code its working the way I wanted.
I really appreciated you help
Toldav.

Please be kind enough to mark this thread as solved.
Thanks.

I'm sorry adam_k I'm new to this I did not know where is the link to make this entry as solved.

At the bottom of the page, there is a section "Has this thread been answered?" and a link to "Mark this thread as solved". Simply click that link.

This question has already been answered. Start a new discussion instead.