Currently working on an application with the following guidelines:

The application is supposed to feature a program that calculates and displays a customer's bill using the interface and figures found here: http://books.google.com/books?id=jGvseZN0g7gC&pg=PA468&lpg=PA468&dq=cable+direct+visual+basic&source=bl&ots=z0KhRX9BGS&sig=8zejHyLyd6Vb8kTVuJIrnsM1p4k&hl=en&ei=fLOHTev5EZOXtwf_zYzTBA&sa=X&oi=book_result&ct=result&resnum=3&ved=0CC4Q6AEwAg#v=onepage&q&f=false

In addition, the following features are required:

  • The premium channels ListBox (channelsListBox) has the following selection: 1, 2, 3, 4, 5, 6. The default selection is 1 when you launch the application
  • Business customers will fill the number of additional connections in a TextBox (connectionsTextBox), which should be empty when you launch the application
  • Please create a CalDue function procedure to calculate total due for both types of customers.
  • Create a ClearLabels Sub Procedure to handle four objects and their associated events.
  • These four objects and events are: channelsListBox.Textchanged, connectionsTextBox.TextChanged, businessRadioButton.Click, and residentialRadioButton.Click
  • When the ClearLabels sub procedure is invoked, it should clear the totalDueLabel to display an empty string.

The problem that I am currently having is that the program does not calculate the correct total amounts for the residential and business customers. I believe it has something to do with the premium channels list and connections text box. Any assistance or advice would be greatly appreciated. Here is the code I have to this point:

Option Explicit On
Option Strict On
Option Infer Off

Public Class Form1

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub
    Private Function CalcResidentialTotalDue(ByVal premiumChannels As Integer) As Decimal

        Const ResidentialProcessing As Decimal = 4.5D
        Const ResidentialBasic As Decimal = 30D
        Const ResidentialPremium As Decimal = 5D

        Return ResidentialProcessing + ResidentialBasic + ResidentialPremium * premiumChannels
    End Function

    Private Function CalcBusinessTotalDue(ByVal premiumChannels As Integer, _
                                          ByVal connections As Integer) As Decimal

        Const BusinessProcessing As Decimal = 16.5D
        Const BusinessFirst10Connections As Decimal = 80D
        Const BusinessAdditionalConnections As Decimal = 4D
        Const BusinessPremiumChannel As Decimal = 50D

        Dim businessBasic As Decimal

        If connections <= 10 Then
            businessBasic = BusinessFirst10Connections
        Else
            businessBasic = BusinessFirst10Connections _
            + ((connections - 10) * BusinessAdditionalConnections)
        End If

        Return BusinessProcessing + businessBasic + BusinessPremiumChannel * premiumChannels
    End Function

    Private Sub ClearLabels(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles businessRadioButton.Click, residentialRadioButton.Click, _
    channelsListBox.TextChanged, connectionsTextBox.TextChanged

        totaldueLabel.Text = String.Empty
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, _
                           ByVal e As System.EventArgs) Handles Me.Load
        channelsListBox.Items.Add("1")
        channelsListBox.Items.Add("2")
        channelsListBox.Items.Add("3")
        channelsListBox.Items.Add("4")
        channelsListBox.Items.Add("5")
        channelsListBox.Items.Add("6")

    End Sub

    Private Sub CalDue(ByVal sender As Object, ByVal e As System.EventArgs) Handles caldueButton.Click
        Dim premiumChannels As Integer = channelsListBox.SelectedIndex
        Dim Connections As Integer
        Dim totalDue As Decimal = 0

        If residentialRadioButton.Checked Then
            totalDue = CalcResidentialTotalDue(premiumChannels)
        Else
            totalDue = CalcBusinessTotalDue(premiumChannels, Connections)
        End If
        totaldueLabel.Text = totalDue.ToString("C2")
    End Sub
End Class

Recommended Answers

All 7 Replies

Member Avatar for Unhnd_Exception

I don't know what it is your doing but i do know your not using the connections textbox. You might as well not have it on there.

In your caldue sub you have a variable named Connections that is never assigned a value and you are passing it to CalcBusinessTotalDue. You might as well pass a zero to the sub, or is that where your connectiontextbox value should be.

Let me know if you need anything on it. I copied it and have it running. It puts numbers up but don't know if there right or not.

Thanks for your reply and I apologize for the ambiguity. Basically you just stated where the problem is, the connectiontextbox value is supposed to be in the caldue sub so that it takes into account the value that the user enters when figuring the total due. You can check your numbers by accessing the link I provided, it has a list of the associated costs that are involved. So for example, if the user were to select the Residential radio button and then selected 3 from the premium channels list, the output should be the processing fee ($4.50) + basic service fee ($30) + 3 * $5 (since it's $5 per premium channel), which equals $49.50. However when I currently run the program with the code I have, it gives me $44.50. So it appears to be $5 short every time.

Member Avatar for Unhnd_Exception

In your caldue sub you are are using the selectedindex property of the listbox. This is going to end up with less than one of what its supposed to be. Basically, 1 = 0 2 = 1. use the selecteditem or selected index + 1 since your items start at 1 and increment by one. Think thats your problem. Change it and you'll get your 49.50.

Thanks, that solved that problem. Now the only issue I see is when the Business radio button is checked, it calculates correctly unless you enter a figure larger than 10 in the connections box. When the figure is larger than 10 the program is supposed to add $4 for each additional connection and it is currently not doing so.

Member Avatar for Unhnd_Exception

Add around () around or math logic. Your not calculating in the right order.

businessBasic =   (   BusinessFirst10Connections + ((connections - 10)   )   * BusinessAdditionalConnections)

That was incorrect. Yours is fine. Jack Daniels wrote that. Look into added the textbox value to the list box value. If they select 6 from the list box and enter 5 in the textbox they should add up.

I chose 6 from the list and entered 12 in the text box with the business radio button selected and it's still giving me $396.50 instead of $404.50 even though I made that change.

Member Avatar for Unhnd_Exception

I get the 404.95 when selecting 6 from the list and 6 from the textbox for a total of 12 connections.

Private Sub CalDue(ByVal sender As Object, ByVal e As System.EventArgs) Handles calduebutton.Click

        Dim premiumChannels As Integer = CInt(channelslistbox.SelectedItem)
        Dim Connections As Integer = CInt(TextBox1.Text) + premiumChannels
        Dim totalDue As Decimal = 0

        If residentialradiobutton.Checked Then

            totalDue = CalcResidentialTotalDue(premiumChannels)
        Else
            totalDue = CalcBusinessTotalDue(premiumChannels, Connections)
        End If
        totalduelabel.Text = totalDue.ToString("C2")
    End Sub

 Private Function CalcBusinessTotalDue(ByVal premiumChannels As Integer, _
                                          ByVal connections As Integer) As Decimal


        Const BusinessProcessing As Decimal = 16.5D
        Const BusinessFirst10Connections As Decimal = 80D
        Const BusinessAdditionalConnections As Decimal = 4D
        Const BusinessPremiumChannel As Decimal = 50D
        Dim businessBasic As Decimal

        If connections <= 10 Then
            businessBasic = BusinessFirst10Connections
        Else
            businessBasic = BusinessFirst10Connections + (connections - 10) * BusinessAdditionalConnections
        End If
        Return BusinessProcessing + businessBasic + BusinessPremiumChannel * premiumChannels
    End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.