VB.Net 2008 Cable Direct Solution

I have completed the code, but I'm having trouble when it comes to

Page 1 of 1

4 Replies - 10367 Views - Last Post: 10 February 2010 - 11:42 AM Rate Topic: -----

#1 ProgrammerStephanie  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 01-November 09

VB.Net 2008 Cable Direct Solution

Posted 01 November 2009 - 12:30 PM

I am having trouble getting the total due for businesses to calculate correctly. Especially when I run the program and alter the amount of connections or the number of premium channels. Any help you could give me would be appreciated. :)

Option Explicit On
Option Strict On
Option Infer Off

Public Class mainForm

	Private Function CalcResidentialTotalDue(ByVal connections As Decimal, _
											 ByVal premium As Decimal, _
											 ByVal Pfee As Decimal, _
											 ByVal Sfee As Decimal) As Decimal

		Const ResidentialProcessing As Decimal = 4.5D
		Const ResidentialBasic As Decimal = 30D
		Const ResidentialPremium As Decimal = 5D
		Dim premiumChannels As Decimal
		Dim charge As Decimal

		lstConnections.SelectedIndex = 0

		premiumChannels = Convert.ToDecimal(lstPremium.SelectedItem)

		charge = ResidentialProcessing + ResidentialBasic _
		+ ResidentialPremium * premiumChannels

		Return charge
	End Function

	Private Function CalcBusinessTotalDue(ByVal connections As Decimal, _
										  ByVal premium As Decimal, _
										  ByVal Pfee As Decimal, _
										  ByVal Sfee As Decimal) As Decimal
		
		Const BusinessProcessing As Decimal = 16.5D
		Const BusinessFirst10Connections As Decimal = 80D
		Const BusinessAdditionalConnections As Decimal = 4D
		Const BusinessPremiumChannel As Decimal = 50D
		Dim premiumChannels As Decimal
		Dim charge As Decimal
		Dim businessBasic As Decimal


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

		premiumChannels=connections*BusinessPremiumChannel


		charge = BusinessProcessing + businessBasic _
		+ BusinessPremiumChannel * premiumChannels



		Return charge

	End Function

	Private Sub ClearTotalDue(ByVal sender As Object, ByVal e As System.EventArgs) _
	Handles radBusiness.Click, radResidential.Click, _
	lstPremium.SelectedValueChanged, lstConnections.SelectedValueChanged

		lblTotalDue.Text = String.Empty
	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		For premiumChannel As Integer = 0 To 20
			lstPremium.Items.Add(premiumChannel.ToString)
		Next premiumChannel

		For connections As Integer = 0 To 100
			lstConnections.Items.Add(connections.ToString)
		Next connections

		lstPremium.SelectedIndex = 0
		lstConnections.SelectedIndex = 0
	End Sub

	Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
		Dim charge As Decimal
		Dim premium As Decimal
		Dim serviceFee As Decimal
		Dim processingFee As Decimal
		Dim premiumChannels As Decimal
		Dim premiumFee As Decimal
		Dim premiumCharge As Decimal
		Dim totalDue As Decimal

		If radResidential.Checked Then
			processingFee = 4.5D
			serviceFee = 30D
			premiumFee = 5D
			premiumChannels = Convert.ToDecimal(lstPremium.SelectedItem)
			premiumCharge = premiumFee * premiumChannels
			totalDue = CalcResidentialTotalDue(charge, premium, processingFee, _
			serviceFee)
			lblTotalDue.Text = totalDue.ToString("C2")
		End If

		If radBusiness.Checked Then
			processingFee = 16.5D
			serviceFee = 80D
			premiumFee = 50D
			premiumChannels = Convert.ToDecimal(lstPremium.SelectedItem)
			premiumCharge = premiumFee * premiumChannels
			totalDue = CalcBusinessTotalDue(charge, premium, processingFee, _
			serviceFee)
			lblTotalDue.Text = totalDue.ToString("C2")
		End If
	End Sub


	Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
		Me.Close()

	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: VB.Net 2008 Cable Direct Solution

#2 ProgrammerStephanie  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 01-November 09

Re: VB.Net 2008 Cable Direct Solution

Posted 01 November 2009 - 12:36 PM

EDIT--This post was originally a double post, so I removed it. (:

This post has been edited by ProgrammerStephanie: 01 November 2009 - 12:42 PM

Was This Post Helpful? 0
  • +
  • -

#3 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: VB.Net 2008 Cable Direct Solution

Posted 01 November 2009 - 01:21 PM

Major design problems - same data duplicated in several locations. You also did not mention the exact requirements. It appears that residential cannot have any connections. I also modified the business connection calculation to remove the first 10 if they want more than 10 connections. There are several ways to divide up the problem, but this one keeps all groups the business and residential logic separately. Also make sure (I can't tell from your code snippet) that either Business or Residential is defaulted to checked so you don;t need to deal with the case of neither being checked. The biggest problem is that your charge and premium variables where uninitialized and therefore zero when calling the Calc Functions.
Option Explicit On
Option Strict On
Option Infer Off

Public Class mainForm

	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 ClearTotalDue(ByVal sender As Object, ByVal e As System.EventArgs) _
	Handles radBusiness.Click, radResidential.Click, _
	lstPremium.SelectedValueChanged, lstConnections.SelectedValueChanged

		lblTotalDue.Text = String.Empty
	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		For premiumChannel As Integer = 0 To 20
			lstPremium.Items.Add(premiumChannel.ToString)
		Next premiumChannel

		For connections As Integer = 0 To 100
			lstConnections.Items.Add(connections.ToString)
		Next connections

		lstPremium.SelectedIndex = 0
		lstConnections.SelectedIndex = 0
	End Sub

	Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
		Dim premiumChannels As Integer = lstPremium.SelectedIndex
		Dim Connections As Integer = lstConnections.SelectedIndex
		Dim totalDue As Decimal = 0

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


	Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Me.Close()
	End Sub
End Class


Was This Post Helpful? 1
  • +
  • -

#4 ProgrammerStephanie  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 01-November 09

Re: VB.Net 2008 Cable Direct Solution

Posted 01 November 2009 - 02:17 PM

Thank you so much! I'd been trying to figure out how to fix the problem. I see what I did wrong. I also apologize for my ambiguity, this was my first post since joining and I didn't think to add the exact specifications for the program. Thanks again! :)
Was This Post Helpful? 0
  • +
  • -

#5 drumhappy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 29-January 10

Re: VB.Net 2008 Cable Direct Solution

Posted 10 February 2010 - 11:42 AM

Hello,

I am doing a programm very similar to this one and I have a couple questions. the "lstpremium" and "lstconnections" I am trying to figure out what these are used for and how they are defined. Thanks



View Postmark.bottomley, on 01 November 2009 - 07:21 PM, said:

Major design problems - same data duplicated in several locations. You also did not mention the exact requirements. It appears that residential cannot have any connections. I also modified the business connection calculation to remove the first 10 if they want more than 10 connections. There are several ways to divide up the problem, but this one keeps all groups the business and residential logic separately. Also make sure (I can't tell from your code snippet) that either Business or Residential is defaulted to checked so you don;t need to deal with the case of neither being checked. The biggest problem is that your charge and premium variables where uninitialized and therefore zero when calling the Calc Functions.
Option Explicit On
Option Strict On
Option Infer Off

Public Class mainForm

	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 ClearTotalDue(ByVal sender As Object, ByVal e As System.EventArgs) _
	Handles radBusiness.Click, radResidential.Click, _
	lstPremium.SelectedValueChanged, lstConnections.SelectedValueChanged

		lblTotalDue.Text = String.Empty
	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		For premiumChannel As Integer = 0 To 20
			lstPremium.Items.Add(premiumChannel.ToString)
		Next premiumChannel

		For connections As Integer = 0 To 100
			lstConnections.Items.Add(connections.ToString)
		Next connections

		lstPremium.SelectedIndex = 0
		lstConnections.SelectedIndex = 0
	End Sub

	Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
		Dim premiumChannels As Integer = lstPremium.SelectedIndex
		Dim Connections As Integer = lstConnections.SelectedIndex
		Dim totalDue As Decimal = 0

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


	Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Me.Close()
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1