Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Hand
ID: 3662899 • Letter: P
Question
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'This application is an order form for a wire
' company that sells spools of copper wiring for $100 each. Delivery charge
' is $10 per spool, $15 for rush delivery. The app displays the status of the
' order including: 1. the number of spools ready to ship; 2. The number of spools
' on back order; 3. the shipping and handling charges; 4. the total amount due.
' The user enters the number of spools and if they want rush delivery. When the
' Calculate Total button is clicked, an input box appears asking the user to enter
' the number of spools currently in stock.
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim intSpoolsOrdered As Integer ' The number of spools ordered
Dim intSpoolsInStock As Integer ' The number of spools in stock
Dim intReady As Integer ' Holds the spools ready to ship
Dim intBackOrder As Integer ' Holds the spools on back order
Dim intSpoolsTotal As Integer ' Holds the total cost of spools ordered
Dim decShipping As Decimal ' Holds the shipping charges
Dim decOrderTotal As Decimal ' Holds the order total
' Call the GetInStock Function
intSpoolsInStock = GetInStock()
' The number of spools the user's wants to order
intSpoolsOrdered = CInt(txtSpoolsOrdered.Text)
' Calculate the Total Cost of Spools ordered
intSpoolsTotal = intSpoolsInStock * 100
decOrderTotal = ShippingCharges(intReady, decShipping) + intSpoolsTotal
'intReady = ReadyToShip(intSpoolsInStock, intSpoolsOrdered)
'lblReadyShip.Text = intReady.ToString()
lblReadyShip.Text = ReadyToShip(intSpoolsInStock, intSpoolsOrdered).ToString()
intBackOrder = BackOrdered(intSpoolsInStock, intSpoolsOrdered)
lblBackOrder.Text = intBackOrder.ToString()
intReady = ReadyToShip(intSpoolsInStock, intSpoolsOrdered)
decShipping = ShippingCharges(intReady, decShipping)
lblShipHandle.Text = decShipping.ToString("c")
lblTotalDue.Text = decOrderTotal.ToString("c")
End Sub
Function GetInStock() As Integer
' This function displays an input box asking the user to
' enter the number of spools in stock. The function returns
' the value entered by the user.
Dim strInput As String ' Holds the user's input
Dim intSpoolsInStock As Integer ' Holds the number of spools in stock
strInput = InputBox("How many spools are in " _
& "stock? ", "Spools in Stock")
intSpoolsInStock = CInt(strInput)
Return intSpoolsInStock
End Function
Function ReadyToShip(ByVal intSpoolsInStock As Integer, ByVal intSpoolsOrdered As Integer) _
As Integer
' This function accepts the number of spools in stock and
' the number of spools ordered. The function returns the
' number of spools ready to ship.
Dim intReady As Integer ' Holds the spools ready to ship
If intSpoolsOrdered < intSpoolsInStock Then
intReady = intSpoolsOrdered
Else
intReady = intSpoolsInStock
End If
Return intReady
End Function
Function BackOrdered(ByVal intSpoolsInStock As Integer, ByVal intSpoolsOrdered As Integer) _
As Integer
' This function accepts the number of spools in stock and
' the number of spools ordered. The function returns the
' number of spools on back order. If no spools are on back
' order, return 0.
Dim intBackOrder As Integer ' Holds the spools on back order
If intSpoolsInStock > intSpoolsOrdered Then
intBackOrder = intSpoolsInStock - intSpoolsOrdered
Else
intBackOrder = intSpoolsOrdered - intSpoolsInStock
End If
Return intBackOrder
End Function
Function ShippingCharges(ByVal intReady As Integer, ByVal decShipping As Decimal) _
As Decimal
' This function accepts the number of spools in ready to ship
' and the per-spool shipping charges. The function returns the
' total shipping and handling charges.
If chkRush.Checked = True Then
decShipping = 15D * (intReady)
Else
decShipping = 10D * (intReady)
End If
Return decShipping
End Function
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtSpoolsOrdered.TextChanged
End Sub
Private Sub Exit_Click(sender As Object, e As EventArgs) Handles Button3.Click
' End the Application by closing the window.
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' This procedure resets the controls to default values
ResetSpools()
ResetDelivery()
End Sub
Private Sub ResetSpools()
' This procedure resets the text box and the check box.
txtSpoolsOrdered.Clear()
chkRush.Checked = False
' Reset the focus to the first fiels
txtSpoolsOrdered.Focus()
End Sub
Private Sub ResetDelivery()
' This procedure clears the labels that display the delivery info.
lblReadyShip.Text = String.Empty
lblBackOrder.Text = String.Empty
lblShipHandle.Text = String.Empty
lblTotalDue.Text = String.Empty
End Sub
Private Sub lblBackOrder_Click(sender As Object, e As EventArgs) Handles lblBackOrder.Click
End Sub
Private Sub lblTotalDue_Click(sender As Object, e As EventArgs) Handles lblTotalDue.Click
End Sub
End Class
Explanation / Answer
The problem is in line
decOrderTotal = ShippingCharges(intReady, decShipping) + intSpoolsTotal ' (A)
here intReady has yet to be intialized because the line intReady = ReadyToShip(intSpoolsInStock, intSpoolsOrdered) should have been before the before A . Swap these lines and your problem is solved.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.