Question How to Auto Generate ID number

stresss

Member
Joined
Aug 11, 2008
Messages
21
Programming Experience
Beginner
Hi all!

I have a question about how to auto generate the next id number.

In my form, I have 5 radiobuttons and one Message ID textbox. When I click on the first radiobutton, the number 1000 will appear in the MsgID textbox, so what I want to achieve is when 1000 is used, and when i close my form and open again, and select the 1st radiobutton, it will show 1001 instead of 1000. Also when I select the 2nd radiobutton, the number 2000 will appear in the MsgID textbox, so likewise how do I get the next available id when 2000 is used?

Thank you very much in advance!!!
 
Hello.

Shall this be kept if the form closes, or if the program closes?
First would a global variable.
Second would put you in the need to save the variable 'somewhere'. You can use My.Settings for this, you could use a XML, INI or plain Textfile for it.

Bobby
 
First you need to decide on where you are going to save the current Id, text file, database, .dat file. Then when you load the form you need to parse what ever file you have decided to use, apply the current number to a session variable and then just increment it each time you push your radio button.

Making any sense??

If not let me know and i'll post some psuedo-code.
 
Hello.

Shall this be kept if the form closes, or if the program closes?
First would a global variable.
Second would put you in the need to save the variable 'somewhere'. You can use My.Settings for this, you could use a XML, INI or plain Textfile for it.

Bobby

It shld be kept even when the program closesm, so when the user create a message with ID as 1000, and closes the program, the next time the user opens it, the ID will be 1001 ( that's for the 1st radiobutton). Then the second radiobutton starts from 2000, so if the user select the 2nd radiobutton and create a message, it will start from 2000. The ID is taken from a table and it's the primary key.
 
First you need to decide on where you are going to save the current Id, text file, database, .dat file. Then when you load the form you need to parse what ever file you have decided to use, apply the current number to a session variable and then just increment it each time you push your radio button.

Making any sense??

If not let me know and i'll post some psuedo-code.

Yeap it make sense. But I don't know how to use the increment method. It will be better if you can provide some code =). The ID is taken from a table, and it's the primary key. And all the table is saved into that table too.
 
Incrementing the variable would be done like so...

VB.NET:
YourVariable += 1

But I get the feeling that, that is not the problem you are asking about. As this is the primary key of your table then you shouldn't need to worry about incrementing it anyway. Hasn' the column got an auto increment feature?
 
Yeap it has an auto increment value of 1. But i want it to be displayed in the textbox. Like if id 1000 is used, then the next available will be 1001 and it will be displayed in the textbox. And if i close the program, and open it again, it will show 1001. Thought of using the incrementing the variable, but i don't know how to implement it.
 
Back
Top