Howard

Howard

  • NA
  • 7
  • 0

Move textbox "price" to Subtotal (and add)

Apr 14 2006 8:52 PM

Hello All,
I'm an e-student at a local college just learning the art of programming for the first time. For the most I’ve been able to muddle through the course using the books and without asking any questions. When I finally posed one, the instructors answer was, to say the lest, mystifying.
With the hopes of getting a real answer I’ve decided to post my question here.

I am writing a relatively simple Sales Receipt program in VB.net with one “add to the list” button, a textbox to type in the “price”, a listbox to keep track of the numbers I’ve entered, and three more textboxes to tally the sub, tax, and total.

I’ve managed to accomplish the basic task of getting the textbox “price” into the listbox and maintaining the cursor focus on the textbox. I know how to calculate the sub, tax and total. But I can’t seem to wrap my head around the “How do I get the listbox accumulated into the subtotal textbox?”  


A code that will add up the items in the list as they accumulate is not feasible. What I need I something a beginner can accomplish like taking the textbox “price” and add it, not only to the listbox as ive done, but also place it into the Subtotal textbox.  Then with each additional "price", keep up with the addition.  

 
Can it be done?

Here is my code so far
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim TextBox1 As Double

        Dim ListBox1 As Double

        Dim txtSubtotal As Double

        Dim txtTax As Double

        Dim txtTotal As Double

 

    End Sub

 

    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click

        'Clear and Retain TextBox1 Focus

        Dim Source As String

        Source = TextBox1.Text

        TextBox1.Text = ListBox1.Items.Add(Source)

        If TextBox1.TextLength = 0 Then

            TextBox1.Focus()

        End If

        If ListBox1.Items.Contains(Source) = True Then

            TextBox1.Clear()

            TextBox1.Focus()

        End If

 

        'Calculate amounts

        Dim SubTotal As Decimal

        Dim CurrentTaxRate As Decimal

        Dim Tax As Decimal

        Dim TotalDue As Decimal

 

        txtSubTotal.Text = SubTotal

        CurrentTaxRate = 0.065

        Tax = CDec(SubTotal * (CurrentTaxRate))

        txtTax.Text = (Tax)

        TotalDue = (SubTotal + (Tax))

        txtTotal.Text = (TotalDue)

    End Sub

    'Format Sales Receipt as currency

    Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave

        TextBox1.Text = FormatCurrency(TextBox1.Text)

    End Sub

End Class

 

Someplace in there I need a running Subtotal for this to work. I hate to ask questions but I'm overlooking somthing and I need help. 

 

Thanks for your time

H~


Answers (5)