rachayita jaiswal

rachayita jaiswal

  • NA
  • 217
  • 106.5k

auto number with string in vb.net

Sep 30 2013 1:24 AM
Hi,

I have created a function to generate auto increment number with string (in some format) - 

Public Sub GetAutoNumber()

        Dim intValue As Integer = 0
        If Not ViewState("intValue") Is Nothing Then
            intValue = CInt(ViewState("intValue"))
        End If
        intValue += 1
        ViewState("intValue") = Convert.ToString(intValue)
        Dim str1 As String = txtObjectProfilesName.Text                 // suppose value is "Testname"
        Dim str2 As String = str1.Substring(0, 3)
        Dim str3 As String = str2.ToUpper()
        Dim str4 As String = cmbObjectProfilesObjectType.Text     // suppose value is "ObjectType"
        Dim str5 As String = str4.Substring(0, 3)
        Dim str6 As String = str5.ToUpper()
        txt_Objectcode.Text = str6 + str3 + Convert.ToString(ViewState("intValue"))
        Dim test As String = txt_Objectcode.Text
    End Sub

i want value like "OBJTES1" in my txt_Objectcode but i am not getting number increment like 1,2,3.... its coming everytime only OBJTES1, diffvalue1,diffvalue1

if i use code - 

Public Sub GetAutoNumber()

        Dim intValue As Integer = 0
        If Not ViewState("intValue") Is Nothing Then
            intValue = CInt(ViewState("intValue"))
        End If
        intValue += 1
        ViewState("intValue") = Convert.ToString(intValue)
        txt_Objectcode.Text = ViewState("intValue")
        Dim test As String = txt_Objectcode.Text
    End Sub

then i am getting auto increment in number like 1,2,3.....

is there anything wrong in code please tell me, its urgent.

Answers (10)