您的位置:首页 > 编程语言 > VB

Auto Increment Invoice Number For Vb.Net

2012-04-02 16:27 507 查看
Let's say you have some invoice numbers which contains Alphabets as well as numeric number.
And you want to increment it one by one.

For Example:

if Invoice number is "AZ99999999" then Next Invoice Number will be "BA00000001"

Notice here that , the invoice number's lenght is 10 Characters out of which first 2 are Alphabets and the rest (8) are Numeric. invoice number can be of any digit with any combination of numerics and alphabets.

The function can be changed to your need very easily. but here i will demonstate for the above example.

Function:

Public Function IncrementInvoice(ByVal strInvoiceNumber As String) As String

If strInvoiceNumber.Length <> 10 Then
Return "Error"
End If

Dim strAlphaPart(1) As Char
strAlphaPart(0) = strInvoiceNumber(0)
strAlphaPart(1) = strInvoiceNumber(1)

Dim IntPart As Int64
IntPart = strInvoiceNumber.Substring(2, 8)

If IntPart = 99999999 Then
If strAlphaPart(1) = "Z" Then
strAlphaPart(0) = Chr(Asc(strAlphaPart(0)) + 1)
strAlphaPart(1) = "A"

IntPart = 1

Return strAlphaPart(0) & strAlphaPart(1) & IntPart.ToString.PadLeft(8, "0")
Else
strAlphaPart(1) = Chr(Asc(strAlphaPart(1)) + 1)
End If

Else
IntPart += 1
Return strAlphaPart(0) & strAlphaPart(1) & IntPart.ToString.PadLeft(8, "0")
End If

End Function


Output:

'outputs example:
strTemp = IncrementInvoice("AA99999998") 'Output will be: "AA99999999"

strTemp = IncrementInvoice("AA00000005") 'Output will be: "AA00000006"

strTemp = IncrementInvoice("AZ00000007") 'Output will be: "AZ00000008"

strTemp = IncrementInvoice("AZ99999999") 'Output will be: "BA00000001"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: