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

VFP 6 - Auto-numbering with the characters 1

Status
Not open for further replies.

millbear

Programmer
May 16, 2002
23
SG
I'm trying to write the code to get the desired result: - CN060901, CN060902, etc...?

CN060901 stands for:-
06 - Year
09 - Month
01 - Serial number (dn_no from the ".dfbnos" table)

dbfnos is the table of the auto-numbering, starting from 01. dn_no is the field name in the table (.dbfnos).

Code:
if empty(thisform.pf.pg1.invno.value)
	select dbfnos
	goto 3		&& Remarks: For Credit Note
	select dbfbcn 
			seek TRIM('CN' + right(str(dtoc(df_date),4),2) + right("00"+alltrim(str(month(df_date))),2) + str(dbfnos.dn_no+1))
	do while not eof() .and. df_ref=alltrim(str(dbfnos.dn_no+1))  
	select dbfnos  
		do while .not. rlock()  
		enddo  
			replace dn_no with dn_no + 1  
			unlock  
			flush   
			select dbfbcn  
			skip  
		enddo   
		select dbfnos	
		
		do while .not. rlock()
		enddo
		replace dn_no with dn_no + 1
		lnextinvno = right("000000"+alltrim(str(dn_no)),3)
		unlock
		flush
	else
		lnextinvno = thisform.pf.pg1.invno.value
	endif

Thanks
millbear

Just a Beginner! Need help badly.
 
Hi Mike

Sorry, i forgot to ask the question earlier.

Originally, the result is 01 when running this line as below.
Code:
seek alltrim(str(dbfnos.dn_no+1))

To achieve the new result is CN060901.
So, i added the following code as below.
Code:
  seek TRIM('CN' + right(str(dtoc(df_date),4),2) + right("00"+alltrim(str(month(df_date))),2) + str(dbfnos.dn_no+1))
. I faced errors instead when running the form.

Wld appreciate if you correct what I'm trying to write.



Thanks
millbear

Just a Beginner! Need help badly.
 
Hi

The error is like 'long string'.


Thanks
millbear

Just a Beginner! Need help badly.
 

OK, here's what you need to do.

Run the code. When the error occurs, click on Suspend. That will take you to the debugger. In the Trace window, rest your mouse on each of the variables in turn in the offending line of code. You will see the actual contents of the variables. That should tell you why you are getting the error.

If that doesn't help, please post the exact error message. Just saying it is like 'long string' doesn't help, I'm afraid.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Just as a starter - right(str(dtoc(df_date),4),2) looks suspicious. The dtoc() function converts a date to a string but the str() function converts a number to a string and can't accept the string being produced by dtoc().

Follow Mike's tips to get into the debugger. You'll find debugging much easier if you break your statement down into several simple stages. You will then be able to see exactly which part of the statement is wrong.

Geoff Franklin
 
The error that I faced is "Function argument value, type, or count is invalid." In the Trace view, it points to
Code:
seek alltrim('CN' + right(str(df_date),2) + right("00"+alltrim(str(month(df_date))),2) + str(dbfnos.dn_no+1))
.

[ponder] Think of re-writing a better code.

Thanks
millbear

Just a Beginner! Need help badly.
 
Well, if the df_date is actually a date field, you are using STR, which is a function for changing numeric value to character. Try useing DTOS or DTOC instead. That should fix your invalid argumnet type.


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Code:
seek alltrim('CN' + right(str(df_date),2) + right("00"+alltrim(str(month(df_date))),2) + str(dbfnos.dn_no+1))

You can't pass a date value to STR(). You'll get exactly the message you're getting. Try this:

Right(Transform(Year(df_date)),2)

For the 2nd expression, you're properly converting the date to number, then to string, and prepending the 0's, but it can be done more easily:

Padl(Month(df_date),2,"0")
 
danfreeman,

Thank you for your valuable post.
The result is 'CN0609' as what I want to see.

Anyway, I do have a problem with the last running serial nos. Now re-writing the code to make the serial nos refreshing from 01 according to every months. For eg, if it is month of Oct, need to set the fresh serial no "01" and thus the result would be CN061001.

Thanks
millbear

Just a Beginner! Need help badly.
 
Hi all experts,

I write the code as below. What I see the result is CN0609 on the report designer when running the form. How to set the serial numbers running according to every month. For example, the df_ref (on the report designer)would be CN060901, CN060902, CN060903, etc when printing out.. If it is month of October, the result will be CN061001, CN061002, so on..

Code:
if empty(thisform.pf.pg1.invno.value)
	select dbfnos
	goto 3		&& Remarks: For Credit Note
	select dbfbcn
	set order to dbfbcna
	
	ldate = date()
	lnextinvno = 'CN'+right(transform(year(ldate)),2)+padl(month(ldate),2,"0")	
	
	seek alltrim('CN'+right(transform(year(ldate)),2)+padl(month(ldate),2,"0"))
	
	do while not eof() .and. df_ref = lnextinvno	&& if not found then create new record
		select dbfnos
		do while .not. rlock()		&& lock record to increase next no. by 1
		enddo
		replace dno_no with dno_no + 1
		lcnno = dno_no + 1				&& this will be the next running no.
		unlock
		flush
		
			append blank
			replace dno_prf with 'CN'
			replace dno_year with right(transform(year(ldate)),2)
			replace dno_mth  with Padl(month(ldate),2,"0")
			replace dno_no   with 01
			unlock
			flush
		select dbfbcn
		skip
	enddo

	else 
		lnextinvno = thisform.pf.pg1.invno.value
endif

For the dbfnos.dbf, how to make the serial numbers running in the same row according to months instead of running in every rows. Click here ~ Simple explaination of table

Thanks
millbear

Just a Beginner! Need help badly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top