My doubt is that is it possible to create incrementing bill no. such as ABC00,ABC01,ABC02,ABC03,ABC04... etc. in ascending list
I already know how to increment with numerical numbers like 0,1,2,3,4, ascending list
I tried concatenation of numerical part with string part.But it works only once;further run leads to error because compiler cannot select maximum from alphanumeric numbers.

This is my code for numerical incrementation

Public Sub AutoEmployeeIDNo()
Dim strselect As String
Dim cmd As New OdbcCommand
Dim conn As OdbcConnection = ConnectionClass.confun
strselect = "Select cuscode from customerdet order by cuscode desc limit 1"
cmd.CommandText = strselect
cmd.CommandType = CommandType.Text
cmd.Connection = conn
Dim value = cmd.ExecuteScalar()
If (value = Nothing) Then
cuscode = 1
cuscode = value + 1
End If
cusRegcode.Text = String.Concat(cuscode)
End Sub
Can anybody help me ..

Recommended Answers

All 4 Replies

You are correct that you must concatenate ABC with the next integer.
I'm guessing that the cuscode is something like ABC01, which is something that you can't handle as you can't increment this by 1.
What you do is cutout the portion of the id that is numeric, increment that and then concatenate it back.
If ABC is a fixed string then nothing to it. If it isn't you will need to do various checks, but that shouldn't be a problem. If ABC is incrementing to keep the numeric part a 2 digit number, then you will need to check the length of the numeric value after incrementing and act accordingly.
Let us know if you need further help.

Could you provide me the code for handling the splitting operations.I have some doubts about it.

This should do it for a fixed ABC (3 chars) and variable length for the numeric part:

dim intvalue = cint(value.substring(4,len(value) - 3)) + 1 
dim newvalue = value.substring(1,3) & intvalue.tostring

If you are planning to have the ABC part variable you might want to thing this in a format like ABC-1. The minus sign will give you the ability to use indexof or split functions.
Also if you want the intvalue to be 01, 02, ... you can multiply the integer by 1000 (or 100 or depending on the number of zeros you want you can adjust) and then

intvalue.substring(2,len(intvalue) - 1)

At last i found the code!!!Yupp..
Public Sub autoincrement()
Dim dset As DataSet
Dim result As String = ""
Dim letter As String = ""
Dim invpre As String = ""
Dim customercode As Integer
Dim strQuery As String = "SELECT customercode FROM custreg order by customercode desc Limit 1"
dset = ExecuteClass.ExecuteNonQuery(strQuery)
Dim invNo As String = dset.Tables(0).Rows(0).Item(0).ToString
For i = 0 To invNo.Length - 1
letter = Convert.ToChar(invNo.Substring(i, 1))
If (Char.IsNumber(letter)) Then
result += letter.ToString()
invpre += letter.ToString()
End If
customercode = Val(result) + 1
cusCode.Text = invpre.ToString + customercode.ToString
End Sub

Be a part of the DaniWeb community

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