Wrox Programmer Forums
|
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2010, 01:47 AM
Registered User
 
Join Date: Sep 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default sub total button

hi all,
i would a code idea how to make this button take in different values of the same transaction hold them until the total button is pressed and it gives a sum total of all the value.any help is highly appreciated
thanks
 
Old September 16th, 2010, 07:49 AM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Default one solution

This will do as you asked, if you need the button to retain the totals even after closing & re-opening the form, you will need to save the runnig total... I would save it using XML or just plain text file depending on the situation. If you need more specific help dont hesitate to re-post with more specific requirements.

If you copy This code, start a new windows form project, open the code window for Form1, Then replace entire page with this code... Good luck

Code:
 Public Class Form1

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Return Then
            Me.ProcessTabKey(True)
            e.SuppressKeyPress = True

        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        POpulateControls() ' Puts all fields & buttons on Form
    End Sub
    Private Sub POpulateControls()
        Dim btn1 As New Button
        Dim btn2 As New Button
        Dim tbox As New TextBox
        'Place  3 Fields on Form
        For j = 1 To 3
            tbox = New TextBox
            tbox.Text = ""
            tbox.Left = 20
            tbox.Top = 20 + (j * 20)
            If j = 3 Then
                tbox.Top = 40 + (j * 20)
                tbox.TabStop = 0
            End If

            Me.Controls.Add(tbox)
        Next

        btn1 = New Button
        btn2 = New Button
        ' PLace "+" Control ON Form
        ' Set properties
        btn1.Top = 80
        btn1.Left = 20
        btn1.Text = "+"
        Me.Controls.Add(btn1)
        AddHandler btn1.Click, New System.EventHandler(AddressOf btn1_Click)


        'PLace GrandTotal Button on Form
        btn2.Top = 80
        btn2.Left = 120
        btn2.Text = "Grand Total"
        Me.Controls.Add(btn2)
        AddHandler btn2.Click, New System.EventHandler(AddressOf btn2_Click)

        tbox = New TextBox
        tbox.Left = 220
        tbox.Top = 30
        tbox.Height = 200
        tbox.Width = 300
        tbox.Multiline = True
        tbox.ScrollBars = ScrollBars.Vertical
        tbox.Text = "Enter a numeric value in each of the top 2 fields. Press the + Button to display the total of the two fields. after entering differing values and pressing + any number of times, press the Totals button"
        Me.Controls.Add(tbox)
    End Sub
    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("The Sum of the totals is..." & Me.Controls(4).Tag)


    End Sub
    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Controls(2).Text = Val(Me.Controls(0).Text) + Val(Me.Controls(1).Text)
        Me.Controls(4).Tag = Val(Me.Controls(4).Tag) + Val(Me.Controls(2).Text)
        Me.Controls(0).Focus()

    End Sub
End Class
This Class will do all the dirty work of placing controls on the form & Sizing ect...
 
Old September 17th, 2010, 11:07 AM
Registered User
 
Join Date: Sep 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks gene bt i jus want it to perform the addition of more than one value and hold the value temporarily until the total button is clicked
 
Old September 18th, 2010, 09:59 AM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Default Sub Total Button

Did you run the code I sent?
I am not sure what you are asking ?

Sounds like maybe Point of sale type transactions that you want to total at the end of the day. Is that closer to what you want?

I'll be happy to help if I knew more specifically what you needed.

I have a Point of sale type form almost ready to post if that will help let me know and I'll finish and post it
 
Old September 20th, 2010, 01:12 AM
Registered User
 
Join Date: Sep 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi Gene,that wud really be of great help.yes i am working on something close to a point of sale,though mine is an electronic tax register bt it does have some similar functions to a point of sale.i may borrow some ideas from you if i c ur post.thanks
 
Old September 20th, 2010, 09:52 AM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Default POS Code.

This Is quick build of a POS with only basic functions... Some Items Are hard coded and you can add others at runtime but they are not saved so what you see originally is what you see each time you open the form.... to save PLU information you would need to use XML or another means of saving the data... But I think this will get you up and running. This Is My own Code, So feel free to use it any way you wish... Also anyone else interested in it is free to use it. If you have any questions just re-Post them.
Code:
 
Public Class Form1
    Private c, u, e, s, t, g As New Label()
    Private Q As New TextBox()
    Private I As New ComboBox()
    Private Lbl As New Label()
    Private n, L As New Button()
    Private lv1 As New ListView()
    Dim x As New xactions
    Dim lox As New List(Of xactions)
    Dim P As New PLU
    Dim LOP As New List(Of PLU)

    Dim LI As New ListViewItem

    Public Sub POPLAbels() ' constructs & Places all Controls on the form... you can place them manually on the form but this is the easiest way to build withouyt screenshots
        c.Location = New Point(35, 9)
        c.Size = New Size(13, 13)
        c.Text = 0
        Me.Controls.Add(c)

        Lbl.Location = New Point(34, 55)
        Lbl.Size = New Size(46, 13)
        Lbl.Text = "Quantity"
        Me.Controls.Add(Lbl)

        Lbl = New Label
        Lbl.Location = New Point(248, 55)
        Lbl.Size = New Size(27, 13)
        Lbl.Text = "Item Name"
        Me.Controls.Add(Lbl)

        Lbl = New Label
        Lbl.Location = New Point(431, 55)
        Lbl.Size = New Size(53, 13)
        Lbl.Text = "Unit Price"
        Me.Controls.Add(Lbl)

        Lbl = New Label
        Lbl.Location = New Point(503, 55)
        Lbl.Size = New Size(80, 13)
        Lbl.Text = "Extended Price"
        Me.Controls.Add(Lbl)

        Q.Location = New Point(27, 73)
        Q.Size = New Size(59, 20)
        Q.Text = ""
        Me.Controls.Add(Q)


        I.Location = New Point(107, 73)
        I.Size = New Size(303, 20)

        Me.Controls.Add(I)


        u.Location = New Point(445, 73)
        u.Size = New Size(53, 13)
        u.Text = 0
        Me.Controls.Add(u)

        e.Location = New Point(518, 73)
        e.Size = New Size(53, 13)
        e.Text = 0
        Me.Controls.Add(e)

        lv1.Location = New Point(12, 111)
        lv1.Size = New Size(650, 164)
        lv1.View = View.Details
        lv1.GridLines = True
        lv1.FullRowSelect = True
        lv1.Columns.Add("Quantity", -2, HorizontalAlignment.Left)
        lv1.Columns.Add("Item", -2, HorizontalAlignment.Center)
        lv1.Columns.Add("Unit Price", -2, HorizontalAlignment.Right)
        lv1.Columns.Add("Extended Price", -2, HorizontalAlignment.Right)

        lv1.Columns(1).Width = 440
        Me.Controls.Add(lv1)
        Me.Height = 500


        Lbl = New Label
        Lbl.Location = New Point(521, 295)
        Lbl.Size = New Size(50, 13)
        Lbl.Text = "Subtotal"
        Me.Controls.Add(Lbl)

        Lbl = New Label
        Lbl.Location = New Point(521, 318)
        Lbl.Size = New Size(25, 13)
        Lbl.Text = "Tax"
        Me.Controls.Add(Lbl)

        Lbl = New Label
        Lbl.Location = New Point(521, 343)
        Lbl.Size = New Size(31, 13)
        Lbl.Text = "Total"
        Me.Controls.Add(Lbl)

        s = New Label
        s.Location = New Point(579, 295)
        s.Size = New Size(80, 13)
        s.Text = 0
        Me.Controls.Add(s)

        t = New Label
        t.Location = New Point(579, 318)
        t.Size = New Size(80, 13)
        t.Text = 0
        Me.Controls.Add(t)

        g = New Label
        g.Location = New Point(579, 343)
        g.Size = New Size(80, 13)
        g.Text = 0
        Me.Controls.Add(g)

        n.Location = New Point(86, 291)
        n.Size = New Size(103, 39)
        n.Text = "New Order"
        Me.Controls.Add(n)

        L.Location = New Point(86, 336)
        L.Size = New Size(103, 39)
        L.Text = "Daily Totals"
        Me.Controls.Add(L)

        Lbl = New Label
        Lbl.AutoSize = True
        Lbl.Location = New Point(248, 280)
        Lbl.Text = "1) Enter a Number IN Quantity TextBox" & vbCrLf
        Lbl.Text = Lbl.Text & "2) Enter An Item in Item Combobox" & vbCrLf
        Lbl.Text = Lbl.Text & "3) Repeat Steps 1 & 2 For each transaction" & vbCrLf
        Lbl.Text = Lbl.Text & "4) Click New Order When finished with order" & vbCrLf
        Lbl.Text = Lbl.Text & "5) Repeat Steps 1-4 For Each Sale" & vbCrLf
        Lbl.Text = Lbl.Text & "6) Click Daily Totals At the end of the day." & vbCrLf
        Me.Controls.Add(Lbl)

        AddHandler I.Validated, New System.EventHandler(AddressOf i_Validated)
        AddHandler n.Click, New System.EventHandler(AddressOf n_Click)
        AddHandler L.Click, New System.EventHandler(AddressOf l_Click)

    End Sub
    Private Sub n_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If g.Text < 1 Then
            MsgBox(" PLease enter one or more transaction then Click New Order Agsain")
            Exit Sub
        Else

            init()
            c.Text += 1
            lv1.Items.Clear()

        End If


    End Sub
    Private Sub l_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        lv1.Clear()
        lv1.View = View.Details
        lv1.Items.Clear()


        Dim lvc As New ColumnHeader
        lvc.Text = "TRANSACTION#"
        lvc.TextAlign = HorizontalAlignment.Center
        lvc.Width = 100
        lv1.Columns.Add(lvc)

        lvc = New ColumnHeader
        lvc.Text = "Number OF Entries"
        lvc.TextAlign = HorizontalAlignment.Center
        lvc.Width = 300
        lv1.Columns.Add(lvc)

        lvc = New ColumnHeader
        lvc.Text = "Grand Total"
        lvc.TextAlign = HorizontalAlignment.Center
        lvc.Width = 80
        lv1.Columns.Add(lvc)
        Dim DT As Double = 0 ' dAILEY Total
        Dim fg As Integer = 0
        For J = 0 To c.Text - 1
            fg = J
            Dim gt As Double = 0
            Dim Q = From GG In lox Where GG.Counter = fg
            For Each gg In Q
                gt = gt + Val(gg.Quantity) * Val(gg.UnitPrice)

            Next

            LI = New ListViewItem
            LI.Text = J + 1
            LI.SubItems.Add(Q.Count)
            LI.SubItems.Add(gt)
            lv1.Items.Add(LI)
            DT = DT + gt
        Next

        LI = New ListViewItem
        LI.Text = "Todays Total"
        LI.SubItems.Add(Format(Now, "Short Date"))
        LI.SubItems.Add(DT)
        lv1.Items.Add(LI)

    End Sub


    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        POPLAbels()
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        lox = New List(Of xactions)
        init()

    End Sub




    Public Sub init()
        I.Items.Clear()

        LOP = New List(Of PLU)
        P = New PLU
        P.Item = "Boots"
        P.Price = "95"
        I.Items.Add(P.Item)
        LOP.Add(P)

        P = New PLU
        P.Item = "Hats"
        P.Price = "28"
        I.Items.Add(P.Item)
        LOP.Add(P)

        P = New PLU
        P.Item = "Gloves"
        P.Price = "10"
        I.Items.Add(P.Item)
        LOP.Add(P)

        P = New PLU
        P.Item = "Shirts"
        P.Price = "14"
        I.Items.Add(P.Item)
        LOP.Add(P)

        P = New PLU
        P.Item = "Sleds"
        P.Price = "12"
        I.Items.Add(P.Item)
        LOP.Add(P)


        I.AutoCompleteMode = AutoCompleteMode.SuggestAppend
        I.AutoCompleteSource = AutoCompleteSource.ListItems

        I.Text = ""
        Q.Focus()

    End Sub
    Private Sub i_Validated(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not IsNumeric(Q.Text) Then Q.Text = 1

        If I.SelectedIndex < 0 Then
            If Len(I.Text) < 2 Then
                MsgBox("Please Enter an item Name ")
                I.Focus()
                Exit Sub

            End If
            P = New PLU
            P.Item = I.Text
            P.Price = InputBox("Please Enter Price For " & I.Text, "New PLU")
            LOP.Add(P)
            I.Items.Add(P)
            SVE()
        Else
            SVE()
        End If
    End Sub
    Private Function Lookup()
        Dim q = From g In LOP Where g.Item = I.Text

        For Each gg In q
            u.Text = gg.Price
            Return gg.Price
        Next

        Return 0
    End Function
    Private Sub SVE()



        x = New xactions
        x.Counter = c.Text
        x.Quantity = Q.Text
        x.Item = I.Text
        x.UnitPrice = Lookup()
        u.Text = x.UnitPrice
        e.Text = x.Quantity * x.UnitPrice

        lox.Add(x)
        LI = New ListViewItem

        LI.Text = x.Quantity
        LI.SubItems.Add(x.Item)
        LI.SubItems.Add(x.UnitPrice)
        LI.SubItems.Add(e.Text)

        lv1.Items.Add(LI)
        GrandTotal(e.Text)
        Q.Text = ""
        I.Text = ""
        u.Text = 0
        e.Text = 0

        Q.Focus()

    End Sub
    Private Sub GrandTotal(ByRef a As String)

        s.Text = (Val(s.Text) + Val(a))
        t.Text = (Val(s.Text) * 0.0725)
        g.Text = Val(s.Text) + Val(t.Text)

        g.Text = Format(g.Text, "Currency")

    End Sub
End Class
<Serializable()> Public Class PLU
    Private _Item As String
    Private _Price As String
    Property Item As String
        Get
            Return _Item
        End Get
        Set(ByVal Value As String)
            _Item = Value
        End Set
    End Property

    Property Price As String
        Get
            Return _Price
        End Get
        Set(ByVal Value As String)
            _Price = Value
        End Set
    End Property
End Class

<Serializable()> Public Class xactions
    Private _Counter As String
    Private _Quantity As String
    Private _Item As String
    Private _UnitPrice As String
    Property Counter As String
        Get
            Return _Counter
        End Get
        Set(ByVal Value As String)
            _Counter = Value
        End Set
    End Property
    Property Quantity As String
        Get
            Return _Quantity
        End Get
        Set(ByVal Value As String)
            _Quantity = Value
        End Set
    End Property
    Property Item As String
        Get
            Return _Item
        End Get
        Set(ByVal Value As String)
            _Item = Value
        End Set
    End Property
    Property UnitPrice As String
        Get
            Return _UnitPrice
        End Get
        Set(ByVal Value As String)
            _UnitPrice = Value
        End Set
    End Property
End Class
 
Old September 20th, 2010, 12:01 PM
Registered User
 
Join Date: Sep 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks gene, i was able to get what i wanted and my code now works.am grateful





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting the Total northwind XSLT 1 April 26th, 2007 03:40 AM
Sub Total Rjh Reporting Services 0 June 21st, 2006 04:11 PM
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
how to use 'Enter' button to trigger a button, thx raybristol ASP.NET 1.0 and 1.1 Basics 1 December 16th, 2005 06:56 AM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.