Click here to Skip to main content
15,886,807 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
suppose i have token no 1 to 200 i want to initialize at the last of month means it will start automatically generate from 1 using vb.net
Posted
Comments
syed shanu 5-Dec-14 1:22am    
need more details.provide sample data and tell us what will be your Input and what you are expecting as output.
tanugarg 5-Dec-14 1:25am    
token no
1
2
3
4
5
.
.
.
.
200
this is automatic generated no in dec 2014
i want to generate a token no from sr.no 1 in jan 2015
Sinisa Hajnal 5-Dec-14 2:24am    
Take the code that generates the numbers and reset it when the year changes. What is the problem? How are you currently generating those numbers?

1 solution

The logic is: NextToken = MAX(Token)+1 Where Month = Current_Month

Let's say you have a class like this:
VB
Public Class TokenData
	Private iToken as Integer = 0
	Private dDate as Date
	
	Sub New(ByVal _Token As Integer, ByVal _Date As Date) 
		iToken = _Token
		dDate = _Date
	End Sub
	
	Public Property Token As Integer
		Get
			Return iToken
		End Get
		Set (ByVal _Token As Integer)
			iToken = _Token
		End Set
	End Property

	Public Property mDate As Date
		Get
			Return dDate
		End Get
		Set (ByVal _Date As Date)
			dDate = _Date
		End Set
	End Property
End Class


To be able to get next Token number from List(of TokenData) for the current month, you need to create linq statement this way:
VB
Sub Main
    'initial Token
    Dim iToken As Integer = 555
    'initial date
    Dim dDate As Date = New Date(2014, 10, 15)

    'declare list of TokenData
    Dim MyData As List(Of TokenData) = New List(Of TokenData)

    'Add initial value
    MyData.Add(New TokenData(iToken, dDate))

    'get next tokens
    Dim i As Integer = 4
    Do While dDate < Date.Today
        dDate = dDate.AddDays(i)
        iToken = MyData.Where(Function(c) c.mDate.Month = dDate.Month And c.mDate.Year=dDate.Year).Select(Function(c) c.Token).DefaultIfEmpty().Max() + 1
        MyData.Add(New TokenData(iToken, dDate))
    Loop

End Sub


Result:
Token     mDate
555       2014-10-15 00:00:00
556       2014-10-19 00:00:00
557       2014-10-23 00:00:00
558       2014-10-27 00:00:00
559       2014-10-31 00:00:00
1         2014-11-04 00:00:00
2         2014-11-08 00:00:00
3         2014-11-12 00:00:00
4         2014-11-16 00:00:00
5         2014-11-20 00:00:00
6         2014-11-24 00:00:00
7         2014-11-28 00:00:00
1         2014-12-02 00:00:00
2         2014-12-06 00:00:00
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900