Código:
Dim Price(100) As Single 'Para declarar las constantes Const Binder_1_Inch_Decimal As Decimal = 1.89 Const Binder_2_Inches_Decimal As Decimal = 1.99 Const Calendars_Decimal As Decimal = 8.49 Const Desktop_Storage_Decimal As Decimal = 4.49 Const Envelopes_Decimal As Decimal = 1.49 Const File_Folders_Decimal As Decimal = 2.79 Const Notebooks_Decimal As Decimal = 1.79 Const Printer_Cartridge_Decimal As Decimal = 99.99 Const Scissors_Decimal As Decimal = 1.79 Const Tape_Decimal As Decimal = 2.99 Private Function CalcTotal() As Single Dim i As Integer Dim Binder_1_Inch_Decimal, Binder_2_Inches_Decimal As String Dim Total, Tax As Single For i = 0 To lstExtPric.Items.Count - 1 lstExtPric.SetSelected(i, True) 'Elimina el caracter $ del String Binder_1_Inch_Decimal = lstExtPric.SelectedItem.trim("$") Total = Total + Val(Binder_1_Inch_Decimal) Next Tax = Total * 0.05 txtTotal.Text = FormatCurrency(Total + Tax) 'Opcional unselecciona lstExtPric If lstExtPric.SelectedIndex <> -1 Then lstExtPric.SetSelected(lstExtPric.SelectedIndex, False) End If Return True End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lstChoice.Items.Add("Binder 1 Inch") lstChoice.Items.Add("Binder 2 Inches") lstChoice.Items.Add("Calendars") lstChoice.Items.Add("Desktop Storage") lstChoice.Items.Add("Envelopes") lstChoice.Items.Add("File Folders") lstChoice.Items.Add("Notebooks") lstChoice.Items.Add("Printer Cartridge") lstChoice.Items.Add("Scissors") lstChoice.Items.Add("Tape") Dim AllText, LineOfText, A As String Dim B() As String Dim s As Integer = 0 End Sub Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click Dim Purchase As Integer Dim Total As Single Purchase = lstChoice.SelectedIndex If lstChoice.SelectedIndex <> -1 And Val(txtQty.Text) > 0 Then 'Añadir la seleccion a la compra lstProduct.Items.Add(lstChoice.SelectedItem) lstPrice.Items.Add(FormatCurrency(Price(Purchase))) lstQty.Items.Add(txtQty.Text) lstExtPric.Items.Add(FormatCurrency(Val(txtQty.Text) * Price(Purchase))) lstTax.Items.Add(FormatCurrency(Val(txtQty.Text) * Price(Purchase) * 0.04)) Call CalcTotal() Else MsgBox("Select Item from List!" & vbCrLf & "Quantity must be greater than 0.", MsgBoxStyle.Critical, "Error") End If End Sub Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReset.Click lstProduct.Items.Clear() lstQty.Items.Clear() lstPrice.Items.Clear() lstExtPric.Items.Clear() lstTax.Items.Clear() txtTotal.Text = "" End Sub Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click Dim s As Integer = lstProduct.SelectedIndex If lstProduct.SelectedIndex <> -1 Then lstProduct.Items.RemoveAt(s) lstQty.Items.RemoveAt(s) lstPrice.Items.RemoveAt(s) lstExtPric.Items.RemoveAt(s) lstTax.Items.RemoveAt(s) Call CalcTotal() Else MsgBox("Select Item from Product List!", MsgBoxStyle.Critical, "Error") End If End Sub Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click End End Sub End Class