473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Generate auto number by code but not repeated.

dear sir,
i wish to generate auto number starting from 1000 to 1000000. but each time number automatically generated no duplicate number generate assign.
thanks,
arun kumar
Oct 13 '06 #1
3 2051
Expand|Select|Wrap|Line Numbers
  1. Public Function Rand(ByVal Min As Long, ByVal Max As Long) As Long
  2.   Rand = Int((Max - Min + 1) * Rnd) + Min
  3. End Function
  4.  
Example:
Expand|Select|Wrap|Line Numbers
  1. NextCard = Rand(1, 52)
  2.  
Will pick a random number between 1 and 52.
Jul 3 '07 #2
Killer42
8,435 Expert 8TB
...Will pick a random number between 1 and 52.
There's actually a function like this in our Articles section. I know, because I wrote it. :)

To cover the second part of the question, you should allocate an array and store the numbers in it. Each time you request a number from your "generate a number between..." function, check it against the array. If it has already been used, ask for another.




Hm... I think I'll write a new version of the random-number routine which won't generate repated numbers. Stay tuned...
Jul 3 '07 #3
Killer42
8,435 Expert 8TB
Took a bit longer than planned, as I had to do some other things. But here is what I've got so far. I think it works.
Jul 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team...
6
by: Sebastien | last post by:
Hi, I am building a products database, linking sales and production. Each part has a unique sales Stock Code and Production Number. The sales stock code is a combination of letters and numbers...
2
by: SalimShahzad | last post by:
Dear Gurus, i had written following codes to auto generate the next claim no Private Const strC = "GCT/02/J/" Private Sub Command1_Click() Dim stra, stre As String Dim intb, intd As Integer...
2
by: G | last post by:
Hello Firends I want a sample code for developing an " auto genearte number " and want to store in database. Please if you find any code please send Thanks in Advance G
8
by: Marc | last post by:
Hi all, I have to generate and send to a printer many 6 digit alphanumeric strings. they have to be unique but I cannot check in a database or something like that if it have already been printed....
1
by: Maninder Karir | last post by:
Hi Im stuck AGAIN!!!!!! Sure its something simple but, Ive put together a code to generate an automatic number everytime i open the work book, However I now would rather only generate the...
4
by: Michiel Rapati-Kekkonen | last post by:
Hi, I would like to generate a versionnumber (and save it in a internal table) on the moment I make a mde. Then there would also be such version tabel in the central, linked data mdb. When...
1
by: abhaya9999 | last post by:
Hi all i am new to mysql and php. i want an urgent help. i am developing an application for an training centre. i want to maintain a student table. To which i only enter his/her name and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.