Also, I have to create something that continually adds each transaction to lblfinalcost. Mine seems to be a little buggy. Right not I have strfinalcost = strginalcost + dblcost. I don't know why it's all weird.
Another question i have is how do I make a number default into the textbox? I want it to say 1, but be able for the user to delete it and then replace it with their own number.
Any help would be appreciated. I made a different topic a few days ago, but this is probably more specific since I made some changes.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'populate listbox
lstproduct.Items.Add("Paper, @ $10.95")
lstproduct.Items.Add("Flash Drive, @ $25.00")
lstproduct.Items.Add("Pencil, @ $0.25")
Exit Sub
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Close()
End Sub
Private Sub btncompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncompute.Click
'declare variables
Dim strproduct As String
Dim intquantity As Integer
Dim dblcost As Double
Static strfinalcost As String
Dim i As Integer
'input from screen
intquantity = (txtquantity.Text)
'string location
strproduct = lstproduct.Items.Item(i)
'Error message for not selecting an item
i = lstproduct.SelectedIndex
If i = -1 Then
MsgBox("Please select an item", MsgBoxStyle.OkOnly, "Error")
Exit Sub
End If
'error message <=0
If intquantity <= 0 Then
MsgBox("Please enter a number greater or equal to 1", MsgBoxStyle.OkOnly, "Error")
Exit Sub
End If
'compute cost for product
If i = 0 Then
dblcost = dblcost + 10.95 * intquantity
ElseIf i = 1 Then
dblcost = dblcost + 25.0 * intquantity
ElseIf i = 2 Then
dblcost = dblcost + 0.25 * intquantity
End If
strfinalcost = strfinalcost + dblcost
'compute depending if payment is in Cash
If radcash.Checked Then
dblcost = dblcost * 0.98
End If
'message box
MsgBox("The cost is $" & dblcost, MsgBoxStyle.OkOnly, "Curent cost")
lblfinalcost.Text = "The total cost of your order is $" & strfinalcost
'final cost string
strfinalcost = String.Format("{0:c}", dblcost)
End Sub
End Class

New Topic/Question
Reply




MultiQuote




|