Hi everyone,
I am writing a code for an order status problem. The user enters the number of spools ordered within a text box, and also has a check box to display a Rush Delivery option. The price per spool is $100. Normal delivery charge is $10 per spool, and rush delivery charge is $15 per spool. The problem specification asks me to create the code for four functions, and three Clear form reset procedures. But it is the functions, called within the Calculate Total button, that are the issue for me.
When the Calculate Total is clicked, an event handler follows, with the calls for the following four functions:
GetInStock function: displays an inputbox, asking the user to enter the number of spools in stock, and returns the value the user entered.
ReadyToShip function: accepts the number of spools in stock and the number of spools ordered as arguments. For example, if the number of spools ordered is 200, and the number of spools in stock is 150, the function returns the number of spools to ship as 150. If the number of spools ordered is 100, and the number of spools in stock is 150, the number of spools to ship is 100.
BackOrdered function: accepts the number of spools in stock and the number of spools ordered as arguments. If the number of spools ordered is 200, and the number of spools in stock is 150, the function returns the number of spools on back order as 50. If the number of spools ordered is 100, and the number of spools in stock is 150, the number of spools on back order is 0.
ShippingCharges function: accepts the number of spools ready to ship, and the per-spool shipping charges as arguments. The function returns the total shipping and handling charges.
On the form, are labels to display the following: the spools ready to ship, the spools on back order, the shipping & handling, and the total due.
My problem, however, is the following. Within the Calculate Total button click event handler, I can only use the above four functions, which return values for the spools in stock, the spools ready to ship, the spools on back order, and the shipping and handling costs. There is no function in the problem specification for calculating the total amount due.
My instructor specifies that:
Other than converting the user's input into the required format, NO calculations are to be done in the CalculateTotal button's Click event. It's code can only include of error trapping, calling procedures, and displaying results.
Is there a way to calculate the total amount due and display it, without:
- Including calculations in the Calcutate Total button click event handler.
- Using module level or global variables.
- Creating another function or procedure within the Calcutate Total button click event handler.
I have thought about using a static variable but I have no idea how that would work. So in the mean time, I have decided to create another function, and include it in the Calcutate Total button click event handler.
I am writing a code for an order status problem. The user enters the number of spools ordered within a text box, and also has a check box to display a Rush Delivery option. The price per spool is $100. Normal delivery charge is $10 per spool, and rush delivery charge is $15 per spool. The problem specification asks me to create the code for four functions, and three Clear form reset procedures. But it is the functions, called within the Calculate Total button, that are the issue for me.
When the Calculate Total is clicked, an event handler follows, with the calls for the following four functions:
GetInStock function: displays an inputbox, asking the user to enter the number of spools in stock, and returns the value the user entered.
ReadyToShip function: accepts the number of spools in stock and the number of spools ordered as arguments. For example, if the number of spools ordered is 200, and the number of spools in stock is 150, the function returns the number of spools to ship as 150. If the number of spools ordered is 100, and the number of spools in stock is 150, the number of spools to ship is 100.
BackOrdered function: accepts the number of spools in stock and the number of spools ordered as arguments. If the number of spools ordered is 200, and the number of spools in stock is 150, the function returns the number of spools on back order as 50. If the number of spools ordered is 100, and the number of spools in stock is 150, the number of spools on back order is 0.
ShippingCharges function: accepts the number of spools ready to ship, and the per-spool shipping charges as arguments. The function returns the total shipping and handling charges.
On the form, are labels to display the following: the spools ready to ship, the spools on back order, the shipping & handling, and the total due.
My problem, however, is the following. Within the Calculate Total button click event handler, I can only use the above four functions, which return values for the spools in stock, the spools ready to ship, the spools on back order, and the shipping and handling costs. There is no function in the problem specification for calculating the total amount due.
My instructor specifies that:
Quote:
Other than converting the user's input into the required format, NO calculations are to be done in the CalculateTotal button's Click event. It's code can only include of error trapping, calling procedures, and displaying results.
- Including calculations in the Calcutate Total button click event handler.
- Using module level or global variables.
- Creating another function or procedure within the Calcutate Total button click event handler.
I have thought about using a static variable but I have no idea how that would work. So in the mean time, I have decided to create another function, and include it in the Calcutate Total button click event handler.
Code:
Public Class frmMain
Private Sub btnCalcTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcTotal.Click
Dim intSpoolsOrdered As Integer
Dim intSpoolsInStock As Integer
Dim intSpoolsReady As Integer
Dim intSpoolsBackOrder As Integer
Dim sngDeliveryPerSpool As Single
Dim sngShippingHandling As Single
Dim sngTotalAmountDue As Single
Const sngPRICE_PER_SPOOL As Single = 100
Const sngDELIVERY_PER_SPOOL = 10
Const sngDELIVERY_RUSH_PER_SPOOL = 15
If txtSpoolsOrdered.Text = String.Empty Then
MessageBox.Show("The field cannot be blank. Enter the number of spools ordered")
Else
If Integer.TryParse(txtSpoolsOrdered.Text, intSpoolsOrdered) = False Then
MessageBox.Show("Enter a number")
Else
If intSpoolsOrdered < 1 Then
MessageBox.Show("The number of spools cannot less than 1")
Else
If chkRushDelivery.Checked = False Then
sngDeliveryPerSpool = sngDELIVERY_PER_SPOOL
Else
sngDeliveryPerSpool = sngDELIVERY_RUSH_PER_SPOOL
End If
intSpoolsInStock = GetInStock()
intSpoolsReady = ReadyToShip(intSpoolsOrdered, intSpoolsInStock)
intSpoolsBackOrder = BackOrdered(intSpoolsOrdered, intSpoolsInStock)
sngShippingHandling = ShippingCharges(intSpoolsReady, sngDeliveryPerSpool)
sngTotalAmountDue = TotalAmount(intSpoolsReady, sngPRICE_PER_SPOOL, sngShippingHandling)
End If
End If
End If
lblReadyShipDisplay.Text = CStr(intSpoolsReady)
lblBackOrderDisplay.Text = CStr(intSpoolsBackOrder)
lblShippingHandlingDisplay.Text = CStr(sngShippingHandling.ToString("c"))
lblTotalDueDisplay.Text = CStr(sngTotalAmountDue.ToString("c"))
End Sub