Auto Generate Sequence Number to file in VBA

Hi Experts,

I am working on one requirement that need to create a interface file, I am coding in the VB. I am not  a familiar with the VB and need help.

The interface file - We need the auto generated sequence number for the file. ( EX: 00000001.txt)  Can we do it in the VB. every time the service generate a new sequence number that not used in previous.
For Example : I have the interface files like 00000001 - 00000012  then next it should crate with 00000013 and so...
if the service is restarted then the counter should not be zero. it should be continue with the same sequence number ( Do we need to use the database for store this (Or) is there any way that we can save the last sequence number in the memory)

Please suggest me on this requnirment.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
If this is only running on one computer, then you could store the last assigned number into a special "control" text file that is only used by this VB program.  At startup it reads the control file if it exists, and stores the number from it into a variable.  Each time it generates a new interface file it adds one to that variable, writes the new value to the control file, closes it, and then creates the interface file.  This way if the program is ended it knows where to pick up next time.

PRAVEEN TAuthor Commented:
Thank you for support.  But there is a possibility for multiple servers to run.

Please suggest
Bill PrewIT / Software Engineering ConsultantCommented:
If multiple servers are all updating the same folder of interface files, and trying to assign the next available sequence number, then yes, you probably need a server based database that they can all talk to and request a new sequence number from.  Database have the appropriate locking to prevent two servers using the same number, etc.  Most database allow tables to have a special sequence number column that can be used when a row is added to generate a new sequence number.

Does the file name really need to be a sequential number as you described?  Or could it be the current date and time stamp down to milliseconds, which would likely prevent collisions, but could still be sorted into a chronological order.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PRAVEEN TAuthor Commented:
Yes, its required sequential.
Bill PrewIT / Software Engineering ConsultantCommented:
Database is your best bet then.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.