Private Sub generateORNumber() Dim con As New SqlConnection(ConnectString()) Dim cd As New SqlCommand Dim lrd As SqlDataReader Try con.Open() cd.Connection = con cd.CommandText = "SELECT count(ornumber) as co,AlphabetID FROM BlueRoomTransactions group by AlphabetID" lrd = cd.ExecuteReader() While lrd.Read() ornum = Convert.ToString(lrd("co")) alpID = Convert.ToString(lrd("AlphabetID")) End While Catch ex As Exception Finally con.Close() End Try ornum = ornum + 1 totalORNUM2 = ornum - 1 txtORNumber.Text = "OR" & Date.Today.ToString("MMddyy") & alphRecursive().ToString & ornum.ToString.PadLeft(4, "0") End Sub Private Function alphRecursive() As String Dim alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray() If ornum > 1 Then alpID += 1 c = alpID ''Reset ornum to zero(0) and add another alphabet on the existing string like 'AA,AB' after it reaches the designated ornum like 1 If c >= alphabet.Length Then ornum = ornum - totalORNUM2 c = 0 Return alphRecursive(c \ alphabet.Length) & alphabet(c Mod alphabet.Length) Else ornum = ornum - totalORNUM2 Return "" & alphabet(c Mod alphabet.Length) End If Else Return "" & alphabet(c Mod alphabet.Length) End If End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)