Click here to Skip to main content
14,599,201 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want my id like SR18/1 and then SR18/2....like this.what will be my code for increment..

What I have tried:

I cant be able to generate SR18/2
Posted
Updated 30-Jan-20 11:22am
Rate this:
Please Sign up or sign in to vote.

Solution 1

It depends on exactly what you want to do, and how you are storing the information. And it's important to think carefully about this: get it wrong and it can cause some horrible effects.

For example, your first problem is simple: how are you using this - is this a single user app, or multiuser? This makes a huge difference: multiuser unique IDs need a heck of a lot more care than single user!
The data storage system will also affect how you generate it: if you are using a database, then you can probably let it do most of the "heavy work" for you as they generally have systems for creating unique values which you can then use as a basis for your specific ID format.

Other problems you need to think about: where does the "SR18" bit come from? When does that change? How does it change? Is the "18" the last two digits of the year? If so, when does that change? January 1st, or at the end of the financial year (April 1st in the UK for tax purposes, but can be any date if it's a companies financial year depending on when the company started trading)? When does the "SR" bit change, and why? What to?

It's not as simple as "this line of code", or even "this method" or "this algorithm" - non-numeric automatic ID values need to be carefully worked out long before you start with code!
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 4

I want my id like SR18/1 and then SR18/2....like this.what will be my code for increment..

What I have tried:

I cant be able to generate SR18/2

I agree with the above: Making something that is alphanumeric poses a lot of questions. The code below is a basic solution to this

As a simple code explanation you use this

Sub Main()
        Dim parentString As String = "SR18/"
        Dim previousInt As Int16 = 35
        Dim currentPart As String = ""

        currentPart = fnMakeNext(parentString, previousInt)

        previousInt = previousInt + 1

        Dim loadsofParts As New List(Of String)

        Dim endofLot As Int16 = 72

        loadsofParts = fnMakeManyParts(previousInt, endofLot, parentString)

        Console.WriteLine("Single Part")
        Console.WriteLine(currentPart)
        Console.WriteLine(vbCrLf)
        Console.WriteLine("Multi Parts")
        For Each s As String In loadsofParts
            Console.WriteLine(s)
        Next
        Console.ReadLine()


    Private Function fnMakeManyParts(previousInt As Short, endofLot As Short, parentString As String) As List(Of String)
        Dim result As New List(Of String)
        For p As Int16 = previousInt To endofLot Step 1
            result.Add(fnMakeNext(parentString, p))
        Next
        Return result
    End Function

    Private Function fnMakeNext(parentString As String, previousInt As Short) As String
        Dim returned As String
        returned = parentString + previousInt.ToString
        Return returned
    End Function


    End Sub



The code only addresses that you want to make an incremental alphanumeric text. It does not address anything about the need of why your are coding this.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100