Page 1 of 1

Transaction No field in a Card File

Posted: Thu May 17, 2007 2:46 pm
by Dyna
Is there any way to have an auto incrementing field in a card file whenever a new record is added.
Would prefer the field to be alphanumeric like RA0001. If not a numeric field is fine. Could it then start with any number rather than starting with 00001.
Thanks

Posted: Wed May 23, 2007 12:31 pm
by COBS Tech Support
Auto-incrementing fields are not standard in CAPITAL but can be simulated.

For a numeric field, assuming the card file TESTCARD, and an auto-incrementing field in it called Autoinc1, then place this in your screen script:

Code: Select all

If Mode = 12
   If IsEmpty(TESTCARD->Autoinc1)
      Declare nNumber Type Numeric
      nNumber := Val(ReadINI("MyCardFile", "AutoInc1", PathData() + "User", "0")) + 1
      WriteINI("MyCardFile", "AutoInc1", NTrim(nNumber), PathData() + "User")
      TESTCARD->Autoinc1 := nNumber
   Endif
Endif


The above assumes that the field Autoinc1 is numeric and also sufficiently large that it will never overflow (contain a number larger than the size of the field).

For an alpha-numeric field the principle is similar, except the field is character type. Use the CBS TranInc() function to increment the transaction number. E.g.,

Code: Select all

Declare cTranNo Type Character
cTranNo := TranInc(ReadINI("MyCardFile", "AutoInc1", PathData() + "User", "0"))
WriteINI("MyCardFile", "AutoInc1", cTranNo, PathData() + "User")
TESTCARD->Autoinc1 := cTranNo

Posted: Wed May 30, 2007 3:15 pm
by Dyna
The script simply puts 1 in the autoinc1 field of every record that I add to the Card file. I would like the field to increment every time a new record is added, so it is pretty much like a record number.

Posted: Wed May 30, 2007 3:25 pm
by COBS Tech Support
I'm sorry but the purpose of this forum is not to provide a free technical consulting/programming service, but rather to provide general guidance to knowledgeable users.

If you're unable to understand the concepts explained here and diagnose and correct problems based on the concepts illustrated, please contact support@capitaloffice.com.au via email and they will put you in touch with a consultant who will do what you require in prepackaged form, for a fee.