0
Invoice Number = Now.Year & Now.Month & ?????

how can i add 5 digits that auto increment when the form loads?

Expected OUTPUT

20120100001

20120100002

Now.Month Problems#

when the month is one digit invoice will be 10 digits while when it is two digits invoice will be 12 digits?

OUTPUT

20121?????

EXPECTED OUTPUT

201201?????

Ton van den Heuvel
  • 10,157
  • 6
  • 43
  • 82

1 Answers1

0

Use Now.Month.ToString("00").

Dim str = DateTime.Now.Year & DateTime.Now.Month.ToString("00")

Try this,

Sub Main()
    For i = 1 To 12
        Console.WriteLine(GetAutonumber(i))
    Next
End Sub

Public Function GetAutonumber(no As Integer) As String
    Dim strNum = no.ToString()
    Dim str = DateTime.Now.Year & DateTime.Now.Month.ToString("00") & New String("0", 5 - strNum.Length) & strNum
    Return str
End Function
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • I just want to add that when the invoiceNumber is incremented the last value of it was saved in mysql database? how can i do that? -Thank you – Charles Flores Feb 01 '12 at 14:07