Results 1 to 6 of 6

Thread: How can I generate Asset number with this format "AST0000001"

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2015
    Posts
    23

    How can I generate Asset number with this format "AST0000001"

    Here's my code for generating Asset number in text box
    Code:
        Dim i As Integer
        Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
            i = i + 1
            txtassetnumber.Text = "AST" & CStr(i)
    
        End Sub
    This code is only displaying AST1 but I need to generate an AST0000001 something like that.. Thank you..
    I just an Entry level programmer in vb.net

  2. #2
    Member
    Join Date
    Nov 2012
    Posts
    62

    Re: How can I generate Asset number with this format "AST0000001"

    You want to format i as a string rather than just convert it.
    This will do it, although there are other options you may want to do some reading around.
    Code:
    txtassetnumber.Text =i.ToString("AST0000000")

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2015
    Posts
    23

    Re: How can I generate Asset number with this format "AST0000001"

    Sir I used your suggestion about generating asset number in that format.. and now my problem is how can I generate without repeating the same value ????any suggestion ??

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,403

    Re: How can I generate Asset number with this format "AST0000001"

    use my.settings to add an integer value, that you update every time you generate a new asset number:

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            My.Settings.lastAssetNumber += 1
            txtassetnumber.Text = My.Settings.lastAssetNumber.ToString("AST0000000")
        End Sub
    
    End Class

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2015
    Posts
    23

    Re: How can I generate Asset number with this format "AST0000001"

    I used this code sir
    Code:
            cmdNew.CommandText = "Select Max(replace(assetnumber,'ast','')) from assetdetails"
    
            cmdNew.CommandType = CommandType.Text
            cmdNew.Connection = myConnection
            'cmdNew.ExecuteNonQuery() '
            reader = cmdNew.ExecuteReader()
            While reader.Read()
                'MsgBox(reader.Item(0))
                value = reader.Item(0)
                'MsgBox(value)
            End While
    
            value = CInt(value) + 1
    
    
            MsgBox(value)
            txtassetnumber.Text = "AST" + value.PadLeft(7, "0")
    
            cmdNew.Dispose()

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,403

    Re: How can I generate Asset number with this format "AST0000001"

    try this:

    Code:
    cmdNew.CommandText = "Select Max(replace(assetnumber,'ast','')) from assetdetails"
    
    cmdNew.CommandType = CommandType.Text
    cmdNew.Connection = myConnection
    
    value = CInt(cmdNew.ExecuteScalar) + 1
    
    txtassetnumber.Text = "AST" + value.PadLeft(7, "0")
    
    cmdNew.Dispose()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width