I'm designing the forms for our business, and am currently working on a Purchase Order form. The aim is to create a form that, when opened, creates a new PO number that runs in sequence.
IE: I open it one time and I have GH-0001, but next time it's opened, we have GH-0002. I'd like to avoid anything based on date and time because those make for very long PO Numbers, and slightly weird.
Any suggestions or redirections are welcome.

Purchase Order Number Generator
Falklian
We intend to have only one purchasing agent working from one machine. So the answer is no to both questions.
How do you store the last PO number in the registry and set it to reset to the next one I'm sorry if this is a stupid question, but I suppose I just don't understand what registry you're talking about.
The actual registry for all my different software
voodooflux
PhaedraC
I would then write a shared method called GetNextPONumber that returns an unused PONumber. This method internally is implemented using an algoritm of your choice. You could for example have two colunns: ID (an int set as uniqueidentifyer) and PONumber (calculated column = "PO" & ID). To be efficient you can create a Sproc or another table that precalculates the next available number.
hth,
Paul
ajedi2k
You could also write your information in an xml config file you could also load this config file using a dataset (is this is easyer for you). I also suggest not writing in the app.config, keep it read only.
http://www.codeproject.com/vb/net/registry_with_vb.asp
http://www.codeproject.com/vb/net/ConfigOpt.asp
Dotnetjunky
ryansingleton ,
If getting and setting a registry entry is too complicated or you have other reasons not to use it, You can very easily save the current number to a text file. Xml is nice, but for one single external piece of data (A number no less) need not be so complicated to store and update beyond this.
Simply break up the string and seperate the numeric part and the alphabet part. Unless you need to prefix the PO in any other way you can hard code that part.
Dim POPrefix as string ="GH-"
Then Merge the actual number with it.
Private PO as int32
textbox1.text=POPrefix & PO.ToString
then calculate the math for the next
PO +=1 or is it PO 1+= (Late day brain here)
Then write your new number to a file to be read back the next time you need to generate the next number.
If there's anything else you can tell us, then perhaps a better solution can be expressed. Otherwise it looks this simple to me.
Edit to Add: Sample code
Public Class Form3
Dim LastPO As String
Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
NextPO()
End Sub
Private Sub NextPO()
Dim NextPO As Integer
Dim ThisPO As String
On Error Resume Next
'ThisPO = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\POapp", "POnumber", "GH-0001")
'Uncomment the above and comment below....
If My.Computer.FileSystem.FileExists("PO.txt") Then
ThisPO = My.Computer.FileSystem.ReadAllText("PO.txt")
Else
ThisPO = Me.lbPODisplay.Text
End If
'through to here to switch to using the registry
LastPO = ThisPO
NextPO = CInt(ThisPO.Substring(4))
NextPO += 1
ThisPO = "GH-" & Format(NextPO, "0000").ToString
Me.lbPODisplay.Text = ThisPO
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\POapp", "POnumber", ThisPO)
'Uncomment above and comment below to switch to using the registry
My.Computer.FileSystem.WriteAllText("PO.txt", ThisPO, False)
End Sub
Private Sub lbPODisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbPODisplay.Click
Me.lbPODisplay.Text = LastPO
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
NextPO()
End Sub
End Class
Randy
Gary Davis
1. As ThE_lOtUs suggested, behaviour will be different if more than one user is able to access the form at any given time. Will your form app run seperately on multiple machines
2. Do you have more than one user
If you answer no to these questions then answer is simple, store either the current or last PO number in the registry and have it reset it to the next one each time your form loads.
Randy
TimA
Ryan,
Doing the exact same thing right now, but don't have time to develop. Was looking for an office template when I saw your post. Would you be willing to share your final template with the generator
Mikeg