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:
Output:
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("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"
相关文章推荐
- MySqlBackup.NET - MySQL Backup Solution for C#, VB.NET, ASP.NET
- VB.Net-->如何使两个(或以上的)文本框(或NumberUpDown)显示相同的内容?
- Windows API Reference for C#, VB.NET
- Dynamic Script for executing in VB.NET
- vb.net 教程 2-3 流程控制:循环语句 For...Next 1
- 开发易(PowerCoder&Designer 1.16 for VB.NET 系列)——大客户与小客户,是向左还是右
- (.NET) IntelliSense difference of Extension Method name in Statement Completion for VB and C#.
- OrFlying For VB.Net 在Asp.Net中的应用
- Auto Complete combo Box(VB.NET Source Use API)
- Create a DLL by CSharp or VB.Net for VBA--摘自网络
- VB.NET:Your Visual Blueprint for Building Versatile Programs
- NScript - A script host for C#/VB.NET/JScript.NET(NScript-.Net语言的脚步解释主机)
- OrFlying For VB.NET 使用说明
- vb.net 教程 2-3 流程控制:循环语句 For...Next 2
- OrFlying For VB.Net 下载连接
- VS.NET 2003 Plugin: Auto Version Increment
- Hands-on Labs for Windows® Workflow Foundation in C# and VB.NET
- NScript - A script host for C#/VB.NET/JScript.NET
- Capture a Debug Log or Trace File and Diagnostics for AutoInvoice
- 如何让oracle里面的主键自动递增 autoincrement primary key for oracle