Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. auto generating number

auto generating number

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GaryKoh
    wrote on last edited by
    #1

    hello i have this problem with auto generation number via using function the coding below is converted from vb6 and it is working in vb6 Public Function autoorderno() As String

    Dim orderno As String
    Dim ordering As New Class1
    Dim order As New ADODB.Recordset
    order.Open "SELECT * FROM orders", cn, adOpenDynamic, adLockOptimistic, adCmdText
    auto = "000000"
    Do While Not order.EOF
    order.Find "orderno ='Ord" & auto & "'"
    If Not order.EOF Then
    auto = Format(Str(Val(Mid$(auto, 5) + 1)), "000000")
    Else
    autoorderno = "Ord" + auto
    Exit Function
    End If
    Loop
    autoorderno = "Ord" + auto
    Set order = Nothing
    End Function

    but some how in vb.net it say "value cannot be generated" may i know what is wrong with the coding thank you in advance Gary

    D 1 Reply Last reply
    0
    • G GaryKoh

      hello i have this problem with auto generation number via using function the coding below is converted from vb6 and it is working in vb6 Public Function autoorderno() As String

      Dim orderno As String
      Dim ordering As New Class1
      Dim order As New ADODB.Recordset
      order.Open "SELECT * FROM orders", cn, adOpenDynamic, adLockOptimistic, adCmdText
      auto = "000000"
      Do While Not order.EOF
      order.Find "orderno ='Ord" & auto & "'"
      If Not order.EOF Then
      auto = Format(Str(Val(Mid$(auto, 5) + 1)), "000000")
      Else
      autoorderno = "Ord" + auto
      Exit Function
      End If
      Loop
      autoorderno = "Ord" + auto
      Set order = Nothing
      End Function

      but some how in vb.net it say "value cannot be generated" may i know what is wrong with the coding thank you in advance Gary

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      GaryKoh wrote: but some how in vb.net it say "value cannot be generated" Where does this message come from? It will not be generated by the code you posted, which is VB6 code, not VB.NET... There is nothing wrong with this code other than it is not very effecient. Order numbers should never be reused, even if they have been deleted. This code will find holes in the order number sequence and re-use them. The detabase should have been written to generate ID's itself. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      G 1 Reply Last reply
      0
      • D Dave Kreskowiak

        GaryKoh wrote: but some how in vb.net it say "value cannot be generated" Where does this message come from? It will not be generated by the code you posted, which is VB6 code, not VB.NET... There is nothing wrong with this code other than it is not very effecient. Order numbers should never be reused, even if they have been deleted. This code will find holes in the order number sequence and re-use them. The detabase should have been written to generate ID's itself. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        G Offline
        G Offline
        GaryKoh
        wrote on last edited by
        #3

        hello dave so how i know you would answer thank you just want to know does the msdn webpage provide the suitable tutorial or faq i need to get the random number result i wish as the coding i provided? can i have a link to the webpage please thank you

        D 1 Reply Last reply
        0
        • G GaryKoh

          hello dave so how i know you would answer thank you just want to know does the msdn webpage provide the suitable tutorial or faq i need to get the random number result i wish as the coding i provided? can i have a link to the webpage please thank you

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          There is no one article that will do what you want. Your requirements are a combination of a bunch of smaller techniques that need to be put together correctly. What's with the "random" order number? I've never seen a requirement where the order number must be random. I've only seen "serial number" type order numbers. How I've seen it done in the past, and I've done this myself, is to have a seperate table in the database that holds your databases status and statistics, such as the last used order number. Your code would call a stored procedure in the database that retrieves the last used order number, increments it, stores it back in the table and creates a blank order record in the "orders" table, using the newly created order number. Then this record is sent back to your program as a dataset (SELECT statement). Your app then fills in the details of the order and writes back the order record, without having to worry about the order number at all. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups