Parsing tender values

The integer in the TENDERTYPE column must be parsed to determine the allowable tenders for display in the Cash Register. This involves taking the total value and subtracting the tender value for each tender type (starting from Misc with a value of 32 and working down to Cash with a value of 1). Each time you subtract a tender value, if the remainder is equal to or greater than 0, then the tender type is allowed.

For example, parsing a TENDERTYPE value of 17 would proceed similar to this:

  1. Is 17-32 (for Misc) >= 0? No, so Misc is not an allowable tender.
  2. Is 17-16 (Escrow) >=0? Yes, so Escrow is an allowable tender.

    Subtract 16 from the total, leaving a remainder of 1.

  3. Is 1-8 (Debit) >=0? No, so Debit is not an allowable tender.
  4. Is 1-4 (Credit) >=0? No, so Credit is not an allowable tender.
  5. Is 1-2 (Check)>=0? No, so Check is not an allowable tender.
  6. Is 1-1 (Cash) >=0? Yes, so Cash is an allowable tender.

    Subtract 1 from the total, leaving a remainder of 0.

You’ll likely want to perform this parsing in a conversion formula so that the allowable tenders can be properly displayed in the Cash Register. This could be handled with this code:

Dim TenderType As Integer
     Dim isCash As Boolean = False
     Dim isCheck As Boolean = False
     Dim isCredit As Boolean = False
     Dim isDebit As Boolean = False
     Dim isEscrow As Boolean = False
     Dim isMisc As Boolean = False
     If ((TenderType - 32) >= 0) Then
         TenderType -= 32
         isMisc = True
     End If
     If ((TenderType - 16) >= 0) Then
         TenderType -= 16
         isEscrow = True
     End If
     If ((TenderType - 8) >= 0) Then
         TenderType -= 8
         isDebit = True
     End If
     If ((TenderType - 4) >= 0) Then
         TenderType -= 4
         isCredit = True
     End If
     If ((TenderType - 2) >= 0) Then
         TenderType -= 2
         isCheck = True
     End If
     If ((TenderType - 1) >= 0) Then
         TenderType -= 1
         isCash = True
     End If