Hi people need codes for displaying serial number in a receipt (ie a unique number after every transaction) here is the receipt code am working on

Private Sub CmdPrint_Click()
'printing a receipt
If MsgBox("Print Receipt?", vbYesNo, "Receipt") = vbYes Then
Printer.Print Tab(30);
Printer.Print Tab(30); "TIKMASH MANAGEMENT LIMITED"
Printer.Print Tab(30); "SERVICE CHARGE PAYMENT"
Printer.Print Tab(30); "KATAMU COURT, PLAINSVIEW, SOUTH B."
Printer.Print Tab(30); "L.R NO. 93/1272."
Printer.Print Tab(30); "TEL: +254 721800003"
Printer.Print
Printer.Print Tab(15); "---------------------------------------------------------------------------------------------------------"
Printer.Print Tab(40); "SERVICE CHARGE RECEIPT"
Printer.Print Tab(15); "---------------------------------------------------------------------------------------------------------"
Printer.Print
Printer.Print Tab(15); "Name:"; Spc(3); FrmTikmash.TxtName.Text
Printer.Print
Printer.Print Tab(15); "Unit NO.:"; Spc(3); FrmTikmash.TxtUnitNo.Text
Printer.Print
Printer.Print Tab(15); "Month:"; Spc(3); FrmTikmash.LblDate2.Caption
Printer.Print
Printer.Print Tab(15); "Amount Paid:"; Spc(3); FrmTikmash.TxtAmount.Text
Printer.Print
Printer.Print Tab(15); "Balance B/F:"; Spc(3); FrmTikmash.TxtBal.Text
Printer.Print
Printer.Print Tab(15); "Total Paid:"; Spc(3); FrmTikmash.TxtTotal.Text
Printer.Print
Printer.Print
Printer.Print
Printer.Print
Printer.Print
Printer.Print
Printer.Print
Printer.Print Tab(15); "Service Charge:"; Spc(3); FrmTikmash.TxtPay.Text
Printer.Print
Printer.Print Tab(15); "Balance B/F:"; Spc(1); ".........................................."
Printer.Print
Printer.Print Tab(15); "Agent's Signature:"; Spc(1); "..........................................."
Printer.Print
Printer.EndDoc
End If
End Sub

Dani AI

Generated

the missing piece is generating and persisting the number. Per ’s questions, decide on a format first. From your example (TK012001), it looks like a fixed prefix "TK01" plus a 4-digit running counter starting at 2001. ’s approach is right; here’s a simple VB6 implementation that stores the last number in the registry so it survives restarts.

' In a .bas module
Private Const RECEIPT_PREFIX As String = "TK01"

Public Function NextReceiptNo() As String
    Dim last As Long
    last = CLng(Val(GetSetting("Tikmash", "Receipts", "LastNo", "2000"))) ' start before 2001
    last = last + 1
    SaveSetting "Tikmash", "Receipts", "LastNo", CStr(last)
    NextReceiptNo = RECEIPT_PREFIX & Format$(last, "0000")
End Function

Use it inside your print click only after the user confirms, and print it on the receipt:

Dim recNo As String
recNo = NextReceiptNo()
Printer.Print Tab(15); "Receipt No:"; Spc(3); recNo

Tips:

  • If more than one PC can print receipts, the registry method will create duplicates. In that case, keep the counter in a shared database/table (identity/auto-increment) or a single shared file with locking.
  • Use Format$(..., "0000") to keep leading zeros.
  • If you ever need to reset (e.g., yearly), reset the stored LastNo before printing the first receipt of the new period.

Recommended Answers

All 3 Replies

What serial number? How is it formatted? How does the subroutine get it?

hi Masterace,

Based on your 2 threads, i understand that solution to your problem could be something like this-

1. create a file to store your last receipt number i.e. "2001" (its last 4 numbers of receipt number u gave TK012001)
2. Every time u want to print a receipt -
a) fetch this number from your file
b) increment this
c) append it with "TK01"
d) restore the incremented number to your file

hope this is what you were looking for...

Pankaj

hi Masterace,

Based on your 2 threads, i understand that solution to your problem could be something like this-

1. create a file to store your last receipt number i.e. "2001" (its last 4 numbers of receipt number u gave TK012001)
2. Every time u want to print a receipt -
a) fetch this number from your file
b) increment this
c) append it with "TK01"
d) restore the incremented number to your file

hope this is what you were looking for...

Pankaj

Hi pankaj

am able to see the code in the receipt but its not updatin wil u please help do not know where to code sorr am a newbie

thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.