Hi, im using Visual Basic 2010, I don't have any sort of database i.e. from Access or anything im literally using VB and thats it. I want to create an automated reference number for my system so every time the user press's 'Create New Log' the form opens and it inputs a reference number in a textbox like this: "C-000000001/WJ/08:JUL:12"

Can anyone help me with how to do this using a code and how to set up the code, i.e where it goes etc etc.

Thanks

Recommended Answers

All 3 Replies

You can save the last used number in a settings variable. If you go to your project properties (see Project menu), then go to the Settings tab, you can add a settings variable of any time and scope. If the numbers are unique for each user then create a User scope variable. If the numbers are unique for all users then create an Application scope variable.

Let's assume you create an integer variable named NextNumber and give it a starting value of 1. You can load the value when the application starts by

Dim nextNum As Integer = My.Settings.NextNumber

And you can save the newest setting on form close by

My.Settings.NextNumber = nextNum

and you can convert nextNum to a zero-padded string by

nextNum.ToString("000000000")

Thats great thanks. ill just check to see if it works, however, can you do a step by step guide on how to add those codes, i.e where they go etc and what items to double click on etc, as im not very good at understanding all of these code words.

Thanks very much

If your project is named "My Project" then go to the menu

Project -> MyProject Properties...

It will be the last or next to last item. You'll see a page of property settings. There will be a vertical stack of categories such as Application, Compile, References, etc. Click on the one named "Settings".

Enter a name for the settings variable, as well as a datatype and scope. If you pick User scope, each logged on user will get their own copy. If you pick "Application" then all users will share the same copy. You can also set an initial value to be used when the app is used for the first time.

The code to load the value at startup goes in the Form_Load sub as in

Public Class Form1

    Private nextNum As UInteger

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        nextNum = My.Settings.NextNumber

    End Sub

To save the last used value put the code ini the Form_Closing event as in

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        My.Settings.NextNumber = nextNum

    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.