Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Number Generator


Number Generator

Author
Message
Sean Downes
Sean Downes
Forum God
Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)

Group: Forum Members
Posts: 11, Visits: 26
Hello as some people know im making my own forms without the use of a database.

I need a unique reference number generator on it as well. Ive managed to make a random number generator however,  i dont want it to be random. I would like it so everytime i press the button, it creates a different number each time but occuring. example: 000001, 000002, 000003 etc and perhaps with the date on it as well like: 000001/04:JUL:12, 000002/04:JUL:12, 000003/04:JUL:12 etc.

Could someone shed some light on how to do so please thanks.

Mark
Mark
Forum God
Forum God (75K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
Here is a quick example. Add a module to your project with this code
Public Function NewNumber() As String
Static intNewNumber As Integer
Dim strNumber As String
Dim strDate As String

    intNewNumber = intNewNumber + 1
    
    strNumber = Format(intNewNumber, "00000#")
    strDate = Format(Now, "dd:MMM:yy")
    
    
    NewNumber = strNumber & "/" & strDate
End Function

And to call it you would do something like this in your form

Private Sub Command1_Click()
    Label1.AutoSize = True
    Label1.Caption = NewNumber
End Sub

Sean Downes
Sean Downes
Forum God
Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)

Group: Forum Members
Posts: 11, Visits: 26
Thanks for that. Although, its not seem to be working. And instead of using a label, i would like to use a textbox for it.

Ive added what you said but it doesnt seem to work this is how i put it:

Private Sub Command1_Click()

OccuranceLog.TextBox22.AutoSize = True

OccuranceLog.TextBox22.Text = NewNumber()

End Sub

Public Function NewNumber() As String

Static intNewNumber As Integer

Dim strNumber As String

Dim strDate As String

intNewNumber = intNewNumber + 1

strNumber = Format(intNewNumber, "C-00000#/WJ")

strDate = Format(Now, "dd:MMM:yy")

 

NewNumber = strNumber & "/" & strDate

End Function

 

The extra C- and /WJ that ive added is just to make a unique reference number as there are a few on my forms.

Its set out as form1 has a button, when i click that button it opens up form2 and inputs some of the data for me like date time etc and now hopefully this reference number.

Am i doing something wrong?

Thanks for your help


Mark
Mark
Forum God
Forum God (75K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
See if this gives you the number in the proper format.

Private Sub Command1_Click()
    TextBox22.Text = NewNumber()
End Sub

Public Function NewNumber() As String
Static intNewNumber As Integer
Dim strNumber As String
Dim strDate As String

    intNewNumber = intNewNumber + 1
    strNumber = Format(intNewNumber, "00000#")

    strDate = Format(Now, "dd:MMM:yy")

 

    NewNumber = "C-" & strNumber & "/" & UCase(strDate) & "/WJ"

End Function

Sean Downes
Sean Downes
Forum God
Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)

Group: Forum Members
Posts: 11, Visits: 26
Greats thanks, ill try that when ive got 5 minutes.

Do i need to create a module for that or can i do it when i double click on the button?

If i do need to create a module, how do i do it properly and whats it for and do i need to make any connections etc. Sorry im really bad at this aha

Sean Downes
Sean Downes
Forum God
Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)

Group: Forum Members
Posts: 11, Visits: 26
Just tried it, however not working again. I recon im doing something wrong, hmmm. Butdont forget i haven't created a database from access or anything, should that make a difference?
Mark
Mark
Forum God
Forum God (75K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
When you say it isn't working, what does that mean? What are the expected results, what are you getting and how do they differ?
Sean Downes
Sean Downes
Forum God
Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)

Group: Forum Members
Posts: 11, Visits: 26
When i press the button to open the form, i expect it to add those details that you put in the code, in the textbox, just like the Date and time etc. But it doesn't. Its not throwing it out for anything, its just not putting the information in
Sean Downes
Sean Downes
Forum God
Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)Forum God (2.5K reputation)

Group: Forum Members
Posts: 11, Visits: 26
And im not getting any text at all in the textbox
Mark
Mark
Forum God
Forum God (75K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
Without seeing how you are trying to accomplish this I can't really help. Can you attach your project?
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search