Announcement

Collapse
No announcement yet.

Increasing Numbers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Increasing Numbers

    How can I create an array that will allow me to increase customer invoice numbers by 1 automatically.
    I tried what I thought would work, but when I reset the program, the numbers go back to 0.
    Any help would be appreciated. Thanks.


    ------------------

  • #2
    I'm not sure how you are implementing your invoicing system, so I'll give you the long-winded discussion from some of my experience as an Applications Programmer.

    First, there should be no real need to use an array to hold invoice numbers, just store the "last invoice number" in a disk file, and update the value in the file as each invoice is used.

    By using a disk file, the invoice number is preserved when the program stops.

    For example:
    Code:
    OPEN "INV_NUM.DAT" FOR INPUT AS #1 
    INPUT #1, Invoice_Num&
    CLOSE #1
     
    INCR Invoice_Num&
    '... create the invoice... 
     
    OPEN "INV_NUM.DAT" FOR OUTPUT AS #1
    PRINT #1, Invoice_Num&
    CLOSE #1
    If you are running a multi-user system, then it can get a bit more complicated, as you have to work out a method to ensure that two separate computers do not try to use the same invoice number...

    One common approach to solve this problem is by opening the file in random access (or binary) mode, locking the file, updating the invoice number and writing it back to the file, all in one operation... As long as the LOCK READ WRITE option is used, only one computer should be able to update the file at any one moment.

    ie:
    Code:
    TYPE InvNumType
      Num AS LONG
    END TYPE
    DIM Inv AS InvNumType
    OPEN "INV_NUM.DAT" FOR RANDOM LOCK READ WRITE AS #1 LEN = LEN(Inv)
    GET #1, 1, Inv
    INCR Inv.Num
    PUT #1, 1, Inv
    CLOSE #1
    Now the only problem is dealing with the problem of abandoning an invoice during creation without "losing" a number from the sequence... Seems simple until you realize that since updating the file, none, one or more numbers could have been "used" by other computers!

    Therefore, I;'d suggest that the invoice number is not allocated until the invoice is completed... ie, do this as the very last step in the process of creating an invoice.

    Multi-user programming can be such fun!



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment

    Working...
    X