.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson
Eminent IT

Post New Resource Bookmark and Share   

Id Functions for VB.Net

Posted By:Narayanan       Posted Date: May 07, 2013    Points: 25    Category:    URL: http://www.dotnetspark.com  

Today we will discuss about the ID. ID is a important portion in all Application specially, ERP. So today will discuss.

              Id means identification of Entry. So ID is important in the Application. ID format are different like EN00001/2012-2013/EN00001/1) .Now we discuss about first format (EN00001/2012-2013). Most of the Company wants to this type Id format. Because Every Financial year, Id starts with 1.So we need to give a Financial Year with Id. Why I put EN with ID. Because It will change based on the Form (like Purchase requisition, Purchase Order and so On). I am just giving a Sample example for this Task.
              Ok, let's start our Coding Section .Before go to Coding Section, we plan, how to get this result?
So First, we will discuss

Create one Module in your Application called "ClsBusiValidation".

              First we identify Character and Number in the String.  How to Indentify Character and Number in the Screen?

 Declare Namespace:

Import System.Text.RegularExpression

Create function for Split Character from String:

Public Shared Function gettingCharacter(ByVal CourNo As String, ByVal flag As String) As String
        Dim result As String = String.Empty
        Dim onlyLastLetter As String = Regex.Replace(CourNo, "[^a-zA-Z]+$", [String].Empty)
        Select Case flag
            Case "Whole"
                result = onlyLastLetter
            Case "Last Character"
                result = onlyLastLetter.Substring(onlyLastLetter.Length - 1)
            Case "First Character"
                result = onlyLastLetter.Substring(0, 1)
            Case "Middle Character"
                Dim index As Integer
                index = onlyLastLetter.Length / 2
                If index Mod 2 = 0 Then
                    result = onlyLastLetter.Substring(index, 1)
                    result = onlyLastLetter.Substring(index - 1, 1)
                End If
        End Select
        Return result
    End Function
Create function for Split Number from String:

Public Shared Function GenerateRunningNumber(ByVal curNo As String) As String
        Dim result As String = String.Empty
        Dim digit() As String = Regex.Split(curNo, "\D+")
        For Each item As String In digit
            If item.Length > 0 Then
                result = item
            End If
        Return result
    End Function

Create increase the value:

Public Shared Function increaseValue(ByVal curVal As Integer) As String
        Dim idx As Integer
        idx = curVal + 1
        Return idx.ToString()
    End Function

Create Function Concanate Prefix Zero and Concanate Character with Id:

Public Shared Function GenerateNextValue(ByVal curval As String, ByVal st As String) As String
        Dim str As String = String.Empty
        If curval > 0 And curval < 10 Then
            str = st + "0000" + curval
        ElseIf curval >= 10 And curval < 100 Then
            str = st + "000" + curval
        ElseIf curval >= 100 And curval < 1000 Then
            str = st + "00" + curval
        ElseIf curval >= 1000 And curval < 10000 Then
            str = st + "0" + curval
        ElseIf curval >= 10000 Then
            str = st + curval
        End If
        Return str
    End Function

Call this Function in the Main form:
        Dim source As String = "DTH11110"
        Dim onlyLetter As String = ClsBusiValidation.gettingCharacter(source, "Whole")
        Dim curNumber As Integer = ClsBusiValidation.GenerateRunningNumber(source)
        Dim onlyNumber As Integer = ClsBusiValidation.increaseValue(curNumber)
        Dim CurrnetId As String = ClsBusiValidation.GenerateNextValue(onlyNumber, onlyLetter)


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend