发票编号自动递增

时间:2012-01-31 09:07:23

标签: vb.net auto-increment increment

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

如何在表单加载时添加5位自动递增的数字?

  

预期的输出

     

20120100001

     

20120100002

Now.Month Problems#

当月份为一位数时,发票将为10位数,而当为两位数时,发票将为12位数?

输出

  

20121 ?????

预期输出

  

201201 ?????

1 个答案:

答案 0 :(得分:0)

使用Now.Month.ToString("00")

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

试试这个,

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