This is my Vb.net Project for company i want to generate code for each individual slip so that i get one field as unique field for that i want to use date & slip no to generate unique key. i have attached screen shot my project in this date 21/12/2011 & slip no is 12 now i want to generate unique number as 21121112 (i.e 21/12/2011 as 211211 & slip no is 12 appended at the end)if u have code then attach with your solution

Attachments app1.png 16.37 KB

You could do something like this where you pass in the string date and the string slip number and it returns the formatted "key".
The culture info was chosen because it was the first one I could find that expects the month to come before the day in a slash-delimited string.

Module Module1
   Function GetId(ByVal strDate As String, ByVal strSlipNo As String) As String
      Dim dt As DateTime = DateTime.Parse(strDate, System.Globalization.CultureInfo.CreateSpecificCulture("de-DE"))
      Return String.Format("{0}{1}{2}{3}",
         dt.Day.ToString().PadLeft(2, "0"),
         dt.Month.ToString().PadLeft(2, "0"),
         dt.Year.ToString().PadLeft(4, "0").Substring(2, 2),
         strSlipNo.PadLeft(2, "0"))

   End Function
   Sub Main()
      Console.WriteLine(GetId("21/12/2011", "44"))
   End Sub

End Module

Edited 4 Years Ago by thines01: clarity

You can create a naming scheme, which you already have. Then generate that name on runtime. I am assuming you are using a database backend?

If so, you can use a primary key as a varchar. Generate the key in application, on save, by:

dim datestr as string = today.year & today.month & today.day & today.second 'varries on your creation time.
'Will create a string = "2012020935"

You can create a naming scheme, which you already have. Then generate that name on runtime. I am assuming you are using a database backend?

If so, you can use a primary key as a varchar. Generate the key in application, on save, by:

dim datestr as string = today.year & today.month & today.day & today.second 'varries on your creation time.
'Will create a string = "2012020935"

Please try the below....

Dim TLDateTime As String
Dim TLDay As String
Dim TLMonth As Integer
Dim TLYear As Integer
TLDay = DateTime.Now.Day
TLMonth = DateTime.Now.Month
TLYear = DateTime.Now.Year
Dim MyDate As New DateTime(TLYear, TLMonth, TLDay)
Dim MyString As String = MyDate.ToString("ddMMyy")
TLDate = TLMonth.ToString + TLDay.ToString + TLYear.ToString
Dim receiptid as String
receiptid=Textbox.Text ' which will have the receipt id
TLDateTime = TLDate  + receiptid
This article has been dead for over six months. Start a new discussion instead.