I just started taking VB 2005 in school and decided to make my own program.
Right now you enter Cost, Rebate and Sold into text boxes respectively. When you get to the Sold textbox their is a textChanged Event which displays the profit while your typing it in. When you’re done hit the "Add" button and it will calculate the profit again and display it in the list box.
This is the error I get: "Conversion from string "" to type 'Double' is not valid."
VB Code:
Public Class business Dim fmtStrg As String = "{0, -19}{1, 12:C}{2, 12:C}{3, 12:C}{4, 12:C}" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lstBox.Items.Add(String.Format(fmtStrg, "Item", "Cost", "Rebate", "Sold", "Profit")) lstBox.Items.Add(String.Format(fmtStrg, "-------------------", "-----------", "-----------", "-----------", "-----------")) End Sub Private Sub txtAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim Item As String Dim Cost, Rebate, Sold, Profit As Double If txtItem.Text = "" Then MsgBox("Cannot have empty item field.", 0, "Error") End If Item = CStr(txtItem.Text) Cost = CDbl(txtCost.Text) Sold = CDbl(txtSold.Text) Rebate = CDbl(txtRebate.Text) Profit = (Sold + Rebate) - Cost lstBox.Items.Add(String.Format(fmtStrg, Item, Cost, Rebate, Sold, Profit)) txtTotalProfit.Text = FormatCurrency(Profit + CDbl(txtTotalProfit.Text)) txtCost.Clear() txtRebate.Text = 0 txtSold.Clear() txtItem.Clear() txtItem.Focus() End Sub Private Sub txtSold_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSold.TextChanged Dim Cost, Rebate, Sold As Double Cost = CDbl(txtCost.Text) Sold = CDbl(txtSold.Text) Rebate = CDbl(txtRebate.Text) txtProfit.Text = CStr((Sold + Rebate) - Cost) End Sub End Class
Thank You.




Reply With Quote