Hi Everyone,
I have a problem with a program I have been assigned thats driving me crazy(short trip) and I hope someone with a fresh eye could point me in the right direction. I'm using Visual Basic 2005 on Win7 and the program is a Windows Form application.
The application has to calculate a total order for wire spools and display the shipping status. The form has a text box to accept the total number of spools being ordered (Integer), labels to display # In Stock, # on Back Order, Shipping & Handling, and Order Total, and buttons for calculate, clear, and exit. The application has four functions called from the Calculate Total button's click event procedure.
It is not calculating the shipping charges and giving me a total or validating my input by not accepting orders for less than 1 spool. also if there are no backordered spools it should return zero. I have fooled with this until I'm sure I have over thought and over complicated it :)
Here is my code:
Public Class Form1
Private Function GetInStock() As Integer
Dim intSpoolinStock As Integer = InputBox("Enter the number of spools in stock")
Return intSpoolinStock
End Function
Private Function ReadyToShip() As Integer
Dim intSpoolReadyShip As Integer
Return intSpoolReadyShip
End Function
Private Function BackOrdered() As Integer
End Function
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
' This procedure calculates the status and total of an order of spools.
Dim decSpoolsTotal As Decimal ' Holds the total cost of spools ordered
Dim decTotalDue As Decimal ' Holds the order total
Dim decShipping As Decimal ' Holds the shipping charges
Dim intReady As Integer ' Holds the spools ready to ship
Dim intBackOrder As Integer ' Holds the spools on back order
Dim intSpoolsOrdered, intSpoolInStock, intSpoolReadyShip As Integer
Dim intSpoolsOnBackOrder As Integer
intReady = ReadyToShip()
txtSpoolsReadyToShip.Text = intReady.ToString("d")
intBackOrder = BackOrdered()
txtSpoolsOnBackOrder.Text = intBackOrder.ToString("d")
decShipping = ShippingCharges()
txtShippingHandling.Text = decShipping.ToString("c")
txtTotalDue.Text = decTotalDue.ToString("c")
decSpoolsTotal = ReadyToShip() * 100D
decTotalDue = ShippingCharges() + decSpoolsTotal
intSpoolInStock = GetInStock()
intSpoolReadyShip = (intSpoolInStock)+(intSpoolsOrdered)
txtSpoolsReadyToShip.Text = intSpoolReadyShip.ToString
intSpoolsOnBackOrder = (intSpoolsOrdered) - (intSpoolInStock)
txtSpoolsOnBackOrder.Text = intSpoolsOnBackOrder.ToString
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' This procedure resets the controls to default values
ChkRushDelivery.Checked = False
txtNumberSpoolsOrdered.Clear()
txtSpoolsReadyToShip.Clear()
txtSpoolsOnBackOrder.Clear()
txtShippingHandling.Clear()
txtTotalDue.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' End the application
Me.Close()
End Sub
Function ShippingCharges() As Decimal
' This function returns the cost of shipping.
Dim decTotalShipping As Decimal ' Holds the total shipping cost
'Dim decSpoolsTotal As Decimal ' Holds the total cost of spools ordered
'Dim decTotalDue As Decimal ' Holds the order total
txtNumberSpoolsOrdered.CausesValidation = False
If ChkRushDelivery.Checked = True Then
decTotalShipping = ReadyToShip() * 15D
Else
decTotalShipping = ReadyToShip() * 10D
End If
Return decTotalShipping
End Function
End Class
Thanks for your help
Update:Thanks,I had a lot more wrong with it than just what you commented on....lol. My teacher went over it with me step by step. So here is the code now:
Public Class Form1
Function GetInStock() As Integer
Dim intSpoolinStock As Integer = InputBox("Enter the number of spools in stock")
Return intSpoolinStock
End Function
Function ReadyToShip(ByVal intSpoolinStock As Integer, ByVal intSpoolsOrdered AS Integer) As Integer
If intSpoolinStock intSpoolsOrdered Then
Return intSpoolsOrdered
Else
Return intSpoolinStock
End If
End Function
Function BackOrdered(intSpoolinStock AS Integer, intSpoolsOrdered As Integer) As Integer
Dim intSpoolsOnBackOrder As Integer
If intSpoolinStock = intSpoolsOrdered Then
intSpoolsOnBackOrder = 0
Else
intSpoolsOnBackOrder = (intSpoolsOrdered - intSpoolinStock)
End If
Return intSpoolsOnBackOrder
End
Copyright © 2024 Q2A.MX - All rights reserved.
Answers & Comments
Verified answer
In your shipping charges function you call the ReadyToShip function.
Private Function ReadyToShip() As Integer
Dim intSpoolReadyShip As Integer
Return intSpoolReadyShip
End Function
You create a variable but never assign a value to it so you will always return a 0 value.