please how can i generate serial numbers like a bank account number from a text box.pls i need ur help i use vb.net

Dani AI

Generated

Generating "bank-like" serials needs two things: a sensible structure (fixed total length, clear segments for whatever you want to encode) and a reliable way to produce the unique portion so you never get collisions. Some replies here experimented with quick random generators; that can work for one-off demos but is risky in production because duplicates are possible and you have no built-in error checking. Also, account-style numbers commonly include a check digit so simple typos are caught.

A practical approach:

  1. Define the format up front (example: 3-digit institution + 3-digit branch + 8-digit sequence + 1-digit check = 15 digits).
  2. Use your database or a sequence/identity column to issue the sequence portion atomically (do not rely on client-side random numbers for uniqueness).
  3. Compute a check digit (Luhn or mod-11) from the digits to catch entry errors.
  4. Validate and store the full number with a UNIQUE constraint so duplicates are rejected if a race occurs; retry generation if an insert fails.

The Luhn check digit is compact and widely used. Example VB.NET functions below compute a Luhn check digit and build a formatted account number from a numeric prefix and a sequence value. The code assumes the prefix contains only digits and that you obtain seq from a safe server-side source (identity/sequence):

Function ComputeLuhnCheckDigit(ByVal digits As String) As Integer
    Dim sum As Integer = 0
    Dim doubleDigit As Boolean = True
    For i As Integer = digits.Length - 1 To 0 Step -1
        Dim d As Integer = CInt(digits(i).ToString())
        If doubleDigit Then
            d = d * 2
            If d > 9 Then d -= 9
        End If
        sum += d
        doubleDigit = Not doubleDigit
    Next
    Dim mod10 As Integer = sum Mod 10
    Return If(mod10 = 0, 0, 10 - mod10)
End Function

Function GenerateAccount(prefix As String, seq As Integer, seqWidth As Integer) As String
    Dim seqPart As String = seq.ToString().PadLeft(seqWidth, "0"c)
    Dim core As String = prefix & seqPart
    Dim check As Integer = ComputeLuhnCheckDigit(core)
    Return core & check.ToString()
End Function

Notes: get seq from the server (identity/sequence), enforce a UNIQUE index on the full number, and validate input characters from any textbox. If numbers must not be guessable, use a secure, nonsequential scheme instead. For quick testing, the examples posted by and show random approaches; is right that real account numbers are structured, so design the segments you need before coding.

Recommended Answers

All 3 Replies

Here is an example of code that will randomize the number and show it in a textbox. I haven't added all of it so that you can learn a little about it as well.

Dim RandomClass As New Random()
        Dim RandomNumber As Integer
        RandomNumber = RandomClass.Next
        TextBox1.Text = RandomNumber

You can also look here:

http://www.winnershtriangle.com/w/VBNetHelp_GeneratingRandomNumbers.asp
and here:
http://articles.techrepublic.com.com/5100-10878_11-5663283.html

try using this code to generate random numbers

Dim a as integer
a = Rnd(10000000) * 10000000000000
textbox1.text= a

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.