[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Help with Register totals and such

I am having some problem with my code checking if the amount that was entered by the cashier is less than the total that is subtracted from.
Here is my code:

Dim Change, LooseChange As Currency
Dim getLooseChange As Boolean

    If txtDigits = "$" Or txtDigits = "" Then
        MsgBox "Your need to enter an amount first", vbInformation
    Else
        If getLooseChange = True Then
            Change = Val(txtDigits.Text - LooseChange)
            Text1 = Change
            GoTo B
        Else
        End If
        Change = Val(txtDigits.Text - lblTaxTotal)
B:
        If Left(Change, 1) = "-" Then
            MsgBox "You need " & Replace(Change, "-", "") & " more to complete this transaction", vbCritical
            getLooseChange = True
            LooseChange = Replace(Change, "-", "")
        Else
            getLooseChange = False
        End If
    End If

txtDigits is the box where the cashier types the amout of money the customer gives to them.
lblTaxTotal is the total amount of the products the customer bought.
Change is the amount the customer bought (lblTaxTotal) minus the amout of money the customer gave to the cashier (txtDigits).

Now it calculates just fine. But once its a negitive number... it tells the cashier that you need XX more to finish the transaction. The getLooseChange doesnt seem to work. Its always false for some reason.

This is where i am stuck. How can i check AGAIN the amount of money the cashier types in the txtDigits box after the amount is needed and again check for a negitive number? I also need it to give change back if the second time around they gave so much over the amout that was due.

Thanks for your time,
David
0
Stealthrt
Asked:
Stealthrt
  • 4
  • 3
  • 3
1 Solution
 
sgayatriCommented:
replace

If Left(Change, 1) = "-" Then

WITH
 
if change < 0 then    

 and remove Replace(Change, "-", "")  statement
 with
   (-1) * change

LooseChange = (-1) * change
0
 
StealthrtAuthor Commented:
Doesnt seem to work.. Seems to do the same thing as it did... heres the modded code:

Dim Change, LooseChange As Currency
Dim getLooseChange As Boolean

    If txtDigits = "$" Or txtDigits = "" Then
        MsgBox "Your need to enter an amount first", vbInformation
    Else
        'If getLooseChange = True Then
        '    Change = Val(txtDigits.Text - LooseChange)
        '    Text1 = Change
        '    GoTo B
        'Else
        'End If
        Change = Val(txtDigits.Text - lblTaxTotal)
B:
        If Change < 0 Then
            MsgBox "You need " & Replace(Change, "-", "") & " more to complete this transaction", vbCritical
            getLooseChange = True
            LooseChange = (-1) * Change
            Text1.Text = LooseChange
        Else
            getLooseChange = False
            txtDigits.Text = "$"
            txtDigits.Visible = False
            cmd0.Visible = False
            cmd1.Visible = False
            cmd2.Visible = False
            cmd3.Visible = False
            cmd4.Visible = False
            cmd5.Visible = False
            cmd6.Visible = False
            cmd7.Visible = False
            cmd8.Visible = False
            cmd9.Visible = False
            cmdPoint.Visible = False
            cmdClear.Visible = False
            cmdGoBack3.Visible = False
            cmdCashTotal.Visible = False
            cmdCheckTotal.Visible = False
            cmdEnterTotalMisc.Visible = False
            cmd5Bill.Visible = False
            cmd10Bill.Visible = False
            cmd20Bill.Visible = False
        End If
    End If

I tested it doing the following

5.00 item
plus tax = 5.46

pay with 4.00

total left to pay says 1.46

the value of LooseChange is 1.46

i put in 1.46

says "You need 4 more to compete this transaction"

the value of LooseChange is 4

???
0
 
sgayatriCommented:
Change = Val(txtDigits.Text - lblTaxTotal)

change the above code to
change = val(txdigits.txt) - val(lbltaxtotal)

and put a message box after every calculation.
cross check your values
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
StealthrtAuthor Commented:
im always getting "0" now for the Change:

if change < 0 then

so therefore i never get the "you need xxx..." although i used the same example as i did the last time...

Still not going anywhere :o/

David
0
 
Noel_CastilloCommented:
try this.

create txtAmount-textbox, lblTotalAmount-label, lblAmountDue-label

you might want to assign the total amount due to the txtAmount as its default value.
lblTotalAmount.Tag, lblAmountDue.Tag and lblAmountDue.Caption contains the total amount due.
txtAmount is the textbox where you will enter the payment(s) made.


Private Sub txtAmount_KeyPress(KeyAscii As Integer)
   If KeyAscii = 13 Then
      DoPayment
   End If
End Sub


Sub DoPayment()

If Trim(txtAmount.Text) = "" Then
   MsgBox "Missing amount entry."
   Exit Sub
ElseIf CDbl(txtAmount.Text) < 0 Then
   MsgBox "The system was expecting a positive amount."
   Exit Sub
End If

If CDbl(txtAmount.Text) >= CDbl(lblAmountDue.Tag) Then
   'the payment is enough
   Dim AmountChange As Double
   AmountChange = CDbl(txtAmount.Text) - CDbl(lblAmountDue.Tag)
End If

txtAmount.Tag = Str(Val(txtAmount.Tag) + CDbl(txtAmount.Text)) 'Get total if multiple payments are made

lblAmountDue.Tag = Format(CDbl(lblTotalAmount.Tag) - Val(txtAmount.Tag), "0.00")
lblAmountDue.Caption = "DUE -> " + Format(Val(lblAmountDue.Tag), "#,###,##0.00")
lblTotPaid.Caption = "PAID -> " + Format(Val(txtAmount.Tag), "#,###,##0.00")

If Val(lblAmountDue.Tag) <= 0 Then
   
   DoPrintOfficialReceipt 'Print Receipt
   
   'show customer's change if there is
   If AmountChange > 0 Then MsgBox "Customer's change -> " & Format(AmountChange,"#,###,##0.00")
   '<-------you can close your payment form at this point
Else 'insuficient payment. ask for additional
   
   txtAmount.Text = ""                 'you can clear the txtamount.caption
   txtAmount.Text = lblAmountDue.Tag   'or assign the remaining balance as its new value.
   txtAmount.SetFocus
End If

End Sub


i tested this code before posting. hope this helps. :)
0
 
sgayatriCommented:
ok.
give a try changing val to cint

also print the individual values of
cint(txtdigits)
and
cint(lbltaxtotal)

and check if you get the integer values of them.

Shall come back after testing the code
0
 
sgayatriCommented:
Dim change As Currency
change = Txtdigits.Text - lbltaxtotal
MsgBox change  
B:
        If change < 0 Then
            MsgBox "You need " & Replace(change, "-", "") & " more to complete this transaction", vbCritical
            ....
.....
...
..


End If
End Sub


''pl check this code again... its working fine for me.
''txtdigits = 5.46 and lbltaxtotal = 4.00 i am getting 1.46 result
''' working for txtdigits = 5.46 and lbltaxtotal = 6.00 too properly

0
 
StealthrtAuthor Commented:
Ok, this is what i have that seems to work:

Dim Change As Currency
Dim LooseChange As Currency

    If txtDigits = "$" Or txtDigits = "" Then
        MsgBox "Your need to enter an amount first", vbInformation
    ElseIf Right(txtDigits, 3) <> "." Then
        MsgBox "you need to enter a correct amount", vbInformation
    Else
        If cmdCashTotal.Tag = "GotChange" Then
            Change = Format(Replace(Val(txtDigits.Text - txtHoldChange), "$", ""), "0.00")
            GoTo B
        Else
            cmdCashTotal.Tag = "NoChange"
            Change = Format(Replace(Val(txtDigits.Text - lblTaxTotal), "$", ""), "0.00")
        End If
B:
        If Change < 0 Then
            MsgBox "You need " & Replace(Change, "-", "") & " more to complete this transaction", vbCritical
            LooseChange = Format(Replace(Change, "-", ""), "0.00")
            txtHoldChange = LooseChange
            cmdCashTotal.Tag = "GotChange"
            txtDigits.ForeColor = &HFF&
            txtDigits.Text = "$" & txtHoldChange
        Else
            txtDigits.Text = "$"
        End If
    End If

If you see a problem in there somewhere then please tell me. I will award points to Noel_Castillo if no one can make my code up top a little cleaner (but still work the same)
0
 
Noel_CastilloCommented:
the code i gave came from my POS system. it looks from your previous posts that you are creating your POS system. you can put some additional features like type of payment (tender. ex. cash, credit card, gift check ....). This justifies multiple payment capability of your system.
0
 
Noel_CastilloCommented:
As mentioned above, Stealthrt will award me the points if theres no further comments are posted. tnx :)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now