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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi All, I'm trying to create a c

Status
Not open for further replies.
Nov 4, 2003
8
CA
Hi All,

I'm trying to create a counter based on page n of m. Here are the example of the data.

Name ADD POSTAL_CODE STREAM PAGE
Johndoe 123 Avenue L1L 2L2 2 1
Johndoe 123 Avenue L1L 2L2 2 2
JaneSmith 999 Avenue M1M 2P2 3 1
JaneSmith 999 Avenue M1M 2P2 3 2
JaneSmith 999 Avenue M1M 2P2 3 3

I'm trying to increments the # then reset it when it checks for unique id.

Please help !!!
Thanks
 
Can you be more specific on what you are trying to do with the data that you posted.....

MM
 
I usually solve this type of problem with a scan assuming that I can get my data file in grouped order:

&&&&&&&&&
GO top
thisid=" "
SCAN

IF name+add+postal_code+PADL(TRANSFORM(stream),3,"0")#thisid
thisid=name+add+postal_code+PADL(TRANSFORM(stream),3,"0")
varpage=1
ENDIF

REPLACE page WITH varpage
varpage=varpage+1
endscan
&&&&&&&&&

Brian
 
Sorry,

I'm trying to create a counter on field called page based on stream and another unique id which is Final_mail

Name ADD POSTAL STREAM PAGE Unique_ID
Johndoe 123 Avenue L1L 2L2 2 1 20
Johndoe 123 Avenue L1L 2L2 2 2 20
JaneSmith 999 Avenue M1M 2P2 3 1 35
JaneSmith 999 Avenue M1M 2P2 3 2 35
JaneSmith 999 Avenue M1M 2P2 3 3 35

The logic would be:

if unique_id = unique_id and stream = stream

page=page+1

else
page = 0

end if

something like this but I'm having a hard time with VFP because this is the 1st time I'm on it.

 
Do you want to enumerate each group separately (first 1 to 2 Johndoe, then 1 to 3 JaneSmith, etc.)?

Is it for a report?

Do you want to print each group on a separate page?

Do you want to keep the numbers with the table or add them dynamically?
 
Stella,

Yes saperately and I want to keep the numbers on the table and it's group by unique_id

 
Then use my posted logic:

GO top
thisid=Unique_ID
SCAN

IF Unique_ID#thisid
thisid=Unique_ID
varpage=1
ENDIF

REPLACE page WITH varpage
varpage=varpage+1
endscan
 
Baltman,

It's almost there but I want to reset the counter to 0 and and still counting when unique_id <> unique_id

GO top
thisid=Unique_id
do while not eof()
SCAN
IF thisid=unique_id
varpage=1
else
varpage=0
ENDIF
REPLACE counter with varpage
varpage=varpage+1
endscan
enddo

this is from your logic I only modified a bit but still not working rite.
 
SCAN...ENDSCAN operates from the top of the dbf to the bottom and auto steps through each record without the need for the DO WHILE...ENDDO.

I messed-up when I copied my own code. Try:

thisid=-1 &&or &quot;XX&quot; if a character

SCAN
IF Unique_ID#thisid
thisid=Unique_ID
varpage=1
ENDIF

REPLACE page WITH varpage
varpage=varpage+1
endscan
 
Hi

1. If you need a temporary cursor or workfile then..

SELECT name,add,postal,stream,page, final_mail ;
FROM myTable INTO CURSOR myCursor READWRITE ;
ORDER BY final_mail, stream

nFinal_mail = 0
nPage = 1

SCAN
IF final_mail # nFinal_mail
nFinal_mail = final_nail
nPage = 1
ELSE
nPage = nPage+1
ENDIF
REPLACE page WITH nPage
ENDSCAN

2. If you need to update the table itself,
Then cretea an index, if you dont have, on STR(final_mail)+STR(stream), and set the order of the table to this index.
Then run the code..

nFinal_mail = 0
nPage = 1

SCAN
IF final_mail # nFinal_mail
nFinal_mail = final_nail
nPage = 1
ELSE
nPage = nPage+1
ENDIF
REPLACE page WITH nPage
ENDSCAN

:)

____________________________________________
Ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top