to create unique reference i had below code in vb6

Dim UNKREFBATCH As String
UNKREFBATCH = "B" & Format(Date, "MMDD") & Format(Time, "HHMMSS")

but the same is not giving correct result in vb.net

 Dim UNKREFBATCH As String

 UNKREFBATCH = "B" & Format(Date.Now, "MMDD") & Format(DateTime.Now, "HHMMSS")

 MsgBox(UNKREFBATCH)

instead of minutes its showing month and showing DD or SS for "DD" or "SS"

How can i get same result as in vb6

Minutes is mm instead of MM

 UNKREFBATCH = "B" & Format(Date.Now, "MMdd") & Format(DateTime.Now, "HHmmss")

this gives result as required

thanks

There is already a builtin way to generate a unique reference. It's called a GUID and you can use it as follows:

Dim g As System.Guid = System.Guid.NewGuid

It will generate a result of the form

e57bf525-4b8e-4d09-98aa-53fe997acfb8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.