Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Samir H.
  Where is Samir H.?
 Yogyakarta
 Indonesia
 Samir H.
 To: JK M
  Where is JK M?
 Meycauayan City
 Philippines
 JK M
 Tags
Subject: RE: help on date and auto numbering..
Thread ID: 268549 Message ID: 268600 # Views: 31 # Ratings: 0
Version: Visual FoxPro 6 Category: VFP and .NET
Date: Tuesday, July 13, 2010 2:52:50 PM         
   


> >
> > Hi,
> >
> > You can use the following logic.
> >
> >
> > x=0
> > nyear=YEAR(ddate)
> > SCAN
> > 	x=x+1
> > 	IF 	nyear!=YEAR(ddate)
> > 		x=1
> > 		nyear=YEAR(ddate)
> > 	ENDIF 
> > 	REPLACE sno WITH RIGHT(STR(YEAR(ddate),4),2)+"-"+PADL(x,2,"0")
> > ENDSCAN 
> > 
> > 

> >
> >
> >
> > Regards
> > Bhushan Sahni
> > Eitzen Group (IT)
> > bsh@eitzen-group.com
> > Visual Foxpro a dream house for developers
>
> Sir could you explain further what those codes do?

Hi JK
You should be able to understand Bhushan's code. How could you do programming otherwise?
Use functions like VAL(), PADL(n,2,"0") and other string functions.
Run the code below and watch, you'll understand how it works.

CLEAR 
CREATE CURSOR xTmp (sno c(5))
INSERT INTO xTmp VALUES ('10-21')
INSERT INTO xTmp VALUES ('10-22')
ddate=DATE()	&& example, we are in this year.
GO BOTTOM
FOR i=1 TO 4	&& we do 4 examples
	?ddate
	nyear=YEAR(ddate)	&& take only the year
	nOnlyTwoDigitsYearFromTheDate = VAL(SUBSTR(DTOS(ddate),3,2))
	cFieldOrVariable = sno
	
	nOnlyTwoDigitsYearFromYourData = VAL(LEFT(cFieldOrVariable ,2))
	nYourValueThatYouWantToIncrement = VAL(RIGHT(cFieldOrVariable ,2))
	
	IF nOnlyTwoDigitsYearFromTheDate > nOnlyTwoDigitsYearFromYourData
		* you have a different year -> set to 1 
		 nYourValueThatYouWantToIncrement = 1
	ELSE 
		* increase the number by 1, since we are in the same year.
		nYourValueThatYouWantToIncrement = nYourValueThatYouWantToIncrement + 1
	ENDIF 
	
	cConvertYearBackToCharacter = LTRIM(STR(nOnlyTwoDigitsYearFromTheDate)) 
	* if the software is used more than 90 years, you must change the line above, similar to the one below.
	cConvertIncrementBackToCharacter = PADL(LTRIM(STR(nYourValueThatYouWantToIncrement)),2,"0") 
	
	* Put the data where you need to. Here we use a cursor (table).
	INSERT INTO xTmp VALUES (cConvertYearBackToCharacter +"-"+cConvertIncrementBackToCharacter )
	BROWSE 	
 	IF i<3
	 	ddate=ddate+365	&& next example, we are in next year.
	ELSE 
	 	ddate=ddate+7	&& Last example, we are in following week, same year.
	ENDIF 
	LOOP
NEXT


Regards
Samir

ENTIRE THREAD

help on date and auto numbering.. Posted by JK M @ 7/13/2010 8:25:45 AM
RE: help on date and auto numbering.. Posted by Bhushan Sahni @ 7/13/2010 8:33:38 AM
RE: help on date and auto numbering.. Posted by JK M @ 7/13/2010 11:48:02 AM
RE: help on date and auto numbering.. Posted by Samir H. @ 7/13/2010 2:52:50 PM
RE: help on date and auto numbering.. Posted by JK M @ 7/13/2010 3:01:08 PM
RE: help on date and auto numbering.. Posted by Koen Piller @ 7/13/2010 12:56:39 PM
RE: help on date and auto numbering.. Posted by JK M @ 7/13/2010 2:37:01 PM
RE: help on date and auto numbering.. Posted by Koen Piller @ 7/13/2010 3:03:03 PM
RE: help on date and auto numbering.. Posted by JK M @ 7/13/2010 3:15:09 PM
RE: help on date and auto numbering.. Posted by ho me @ 7/14/2010 5:58:21 PM
RE: help on date and auto numbering.. Posted by Christian Tabligan @ 7/15/2010 2:57:22 AM
RE: help on date and auto numbering.. Posted by JK M @ 7/15/2010 5:51:26 AM
RE: help on date and auto numbering.. Posted by Christian Tabligan @ 7/15/2010 6:20:28 AM