Results 1 to 3 of 3

Thread: Labels changing depending on value in other labels

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2013
    Location
    Ireland
    Posts
    25

    Unhappy Labels changing depending on value in other labels

    I am creating a POS system and on the subtotal page I have various labels such as 'cash', 'card', 'voucher' etc. Say for example a customers total comes to £20 and they want to pay £10 of it in cash and the other £10 with their card, I am having problems getting the labels to total up as they should. The 'total tendered' label displays 0.000 even though it should say £20.00 and the balance and change labels always display 0.00 even if they should say other. I know this is very basic but I have tried to figure this other for ages now and im getting nowhere. I have also tried calling values in from the database but have had no joy with that either. Thanks.
    (I only included one payment button click event as they are all the same except for the labels name changing e.g. lblcash.text would say lblcard.text in the card click event.)

    Code:
     Private Sub btnCash_Click(sender As Object, e As EventArgs) Handles btnCash.Click
    
            'Payment methods...........??
            '2 cash entries
            'cash and card
            'gift voucher and cash
            'gift voucher and card
    
            'HAVING PROBLEMS GETTING CARD AND GIFT VOUCHERS TOGETHER WITH OTHER METHODS
    
            If txtCash.Text = "" Then
                MessageBox.Show("Please enter amount")
            ElseIf txtCash.Text >= "0.00" Then
    
                lblCash.Text = txtCash.Text
                lblCash.Text = FormatCurrency(lblCash.Text, 2)
    
                lblTotTend.Text = (lblCash.Text) + (lblCredit.Text) + (lblVoucher.Text) + (lblOther.Text)
                lblTotTend.Text = FormatCurrency(lblTotTend.Text, 2)
    
                'DISPLAYING AS £0.00
                lblBALANCE.Text = (lblTOTALDUE.Text) - (lblTotTend.Text)
                lblBALANCE.Text = FormatCurrency(lblBALANCE.Text, 2)
    
                If lblBALANCE.Text < "0.00" Then
                    lblBALANCE.Text = "£0.00"
                End If
    
                lblChange.Text = (lblTotTend.Text) - (lblTOTALDUE.Text)
                lblChange.Text = FormatCurrency(lblChange.Text, 2)
    
                If lblChange.Text <= "£0.00" Then
                    lblChange.Text = "£0.00"
                End If
    
                txtCash.Text = ""
    
                SqlStr = "UPDATE Subtotal SET CASH = '" & lblCash.Text & "'"
                With CMD
                    .Connection = CN
                    .CommandType = CommandType.Text
                    .CommandText = SqlStr
                End With
                DataP = CMD.ExecuteScalar
    
                SqlStr = "UPDATE Subtotal SET CHANGE = '" & lblChange.Text & "'"
                With CMD
                    .Connection = CN
                    .CommandType = CommandType.Text
                    .CommandText = SqlStr
                End With
                DataP = CMD.ExecuteScalar
    
                SqlStr = "UPDATE Subtotal SET BalanceRemain = '" & lblBALANCE.Text & "'"
                With CMD
                    .Connection = CN
                    .CommandType = CommandType.Text
                    .CommandText = SqlStr
                End With
                DataP = CMD.ExecuteScalar
    
                SqlStr = "UPDATE Subtotal SET TotalTendered = '" & lblTotTend.Text & "'"
                With CMD
                    .Connection = CN
                    .CommandType = CommandType.Text
                    .CommandText = SqlStr
                End With
                DataP = CMD.ExecuteScalar
            End If
    
            SqlStr = "INSERT INTO SalesLog(ReceiptID) SELECT Id FROM Subtotal"
            With CMD
                .Connection = CN
                .CommandType = CommandType.Text
                .CommandText = SqlStr
            End With
            DataP = CMD.ExecuteNonQuery
    
            SqlStr = "INSERT INTO TransactionLog(ReceiptID) SELECT Id FROM Subtotal"
            With CMD
                .Connection = CN
                .CommandType = CommandType.Text
                .CommandText = SqlStr
            End With
            DataP = CMD.ExecuteNonQuery
    
            ' Added this statement to try solve problem with totaltendered label
            SqlStr = "SELECT SUM(TotalTendered) FROM Subtotal"
            With CMD
                .Connection = CN
                .CommandType = CommandType.Text
                .CommandText = SqlStr
            End With
            lblTotTend.Text = CMD.ExecuteScalar
            lblTotTend.Text = FormatCurrency(lblTotTend.Text, 2)
    
            'UPDATES THE PRICE LABEL TEXTBOX WITH THE LATEST PRICE TOTAL WITHIN THE ACTIVE TABLE!!
            SqlStr = Nothing
            SqlStr = "SELECT SUM(Price) FROM Active"
            With CMD
                .Connection = CN
                .CommandType = CommandType.Text
                .CommandText = SqlStr
            End With
            lblTOTALDUE.Text = CMD.ExecuteScalar
            ' lblTOTALDUE.Text = FormatCurrency(lblTOTALDUE.Text, 2)
    
            If lblBALANCE.Text = "£0.00" Then
                Reset()
                Application.DoEvents()
                'TILL DRAWER OPEN
                Threading.Thread.Sleep(5000)
                Me.Close()
                Login.Show()
            End If

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Labels changing depending on value in other labels

    Your Problem:
    You are calculation with TEXT!
    For example:
    Code:
    lblTotTend.Text = (lblCash.Text) + (lblCredit.Text) + (lblVoucher.Text) + (lblOther.Text)
    All the .Text properties are holding STRINGS. Even if you format that String to a currency-format it will remain a string.
    In order to do correct calculations you need the parse those strings into numeric variables, do the calculations on them and then display the resultion number in a label or textbox using to .To String Method!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2013
    Location
    Ireland
    Posts
    25

    Re: Labels changing depending on value in other labels

    Yeah but I obviously got mistaken as the values in the labels are all numeric.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width