Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counter

Status
Not open for further replies.

mafandon

IS-IT--Management
Jun 6, 2002
1
US
I've played w/ the count command in Clipper5. No luck so far... was wondering if anyone had an idea on this...

I've got one field that has a code. Another field that has a sequential number. I'd like to be able to put in a code for a record and have it look up the NEXT number in the corresponding field.

Example, I'm adding a new record w/ a code of "A". I would like it to look up the number (how many records that are "A's") and automatically put in the next number.

Thank you for any help.
 
cCode := "A"
nCount := 0

Count all for Code = cCode to nCount

select Database
insert // or use AddRec()
lock record
replace Code with aCode
replace Count with nCount
replace Desc with "Count " + LTrim(Str(nCount)) + " for code " + cCode + " added."
commit
unlock record

// Sorry, just typing from memory, haven't done any clipper lately

HTH, TonHu
 
I would maintain an index on codefield + STR(number,5)
called [codeseq]

USE mydatabase EXCLUSIVE
IF NETERR()
RETURN
ENDIF
SET INDEX TO codeseq

Then when I add a new record with a code = 'A' (say)

SET SOFTSEEK ON
SET EXACT OFF

SEEK 'B'
SKIP -1
mnextnum = number+1

APPEND BLANK
REPLACE code WITH 'A'
REPLACE number with mnextnum



Hope this helps
Jim

 
try this...

list := {}
dbgotop()
index on field->yourfiled to temp
while !eof()
if left( field->yourfield,1 ) == "A"
aadd( list, recno() )
endif
dbskip( 1 )
enddo

lastnum := list[ LEN( list ) ]

newnum := ( VAL(ubstr( lastnum, 2, LEN(lastnum) )+1 )


delete temp.ntx

bobby

p.s. arrays are faster than most operations...they use less memory than others. also you will have less VAR symbols in your EXE file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top