[2005] auto-generated account no.. yyyy-9999
i would just like to ask how would be the code for this: yyyy-9999 in vb.net..
yyyy - for the current year
9999 - for the record number
like for instance, for the new record it will be 2008-0001... then for the next record it will be 2008-0002 and so on.. and then if the year ended like for example if the year turns to 2009, the outcome will be 2009-0001... the record will be back to the 0001 and the year will be automatically change to the current year.. that's how it is..
any suggestion how can i do that? i'm just a beginner in vb.net.. i want your help..thanks in advance.
Re: [2005] auto-generated account no.. yyyy-9999
vb.net Code:
Dim recNo As String = Date.Now.ToString("yyyy-9999")
Re: [2005] auto-generated account no.. yyyy-9999
Quote:
Originally Posted by jmcilhinney
vb.net Code:
Dim recNo As String = Date.Now.ToString("yyyy-9999")
when i do that.. it will be automatically back to 0001 record for the next year?
Re: [2005] auto-generated account no.. yyyy-9999
Sorry. I probably should have read your first post a bit more carefully. I really only showed how to format the date into the value. To do what you ask you would need to store the last year used and the last record number used, probably in a database so that they are persisted between sessions. You'd get those values into variables and then when you wanted to generate a new record you'd do something like this:
vb.net Code:
Dim currentYear as Integer = Date.Now.Year
If currentYear = lastYear Then
'The current year is the same as the last year used so increment the record number.
recordNumber += 1
Else
'The current year is later than the last year used so update the last year and reset the record number.
lastYear = currentYear
recordNumber = 1
End If
Dim recordID As String = String.Format("{0}-{1:0000}", lastYear, recordNumber)
Re: [2005] auto-generated account no.. yyyy-9999
Quote:
Originally Posted by jmcilhinney
Sorry. I probably should have read your first post a bit more carefully. I really only showed how to format the date into the value. To do what you ask you would need to store the last year used and the last record number used, probably in a database so that they are persisted between sessions. You'd get those values into variables and then when you wanted to generate a new record you'd do something like this:
vb.net Code:
Dim currentYear as Integer = Date.Now.Year
If currentYear = lastYear Then
'The current year is the same as the last year used so increment the record number.
recordNumber += 1
Else
'The current year is later than the last year used so update the last year and reset the record number.
lastYear = currentYear
recordNumber = 1
End If
Dim recordID As String = String.Format("{0}-{1:0000}", lastYear, recordNumber)
thanks for the reply..it was a great help for me..
Re: [2005] auto-generated account no.. yyyy-9999
Re: [2005] auto-generated account no.. yyyy-9999
Where are you storing the "current year" in use?
Is this all in a database?
How do you expect to get the "last sequence number" that was used for the year desired?
Note that we do exactly what you are asking in our financial applications - but without know a bit more about your situation it would be useless for me to show you how we accomplish this.
Re: [2005] auto-generated account no.. yyyy-9999
Quote:
Originally Posted by ashley_10
can you help me?
With what? I thought I already had.