Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How do I generate a 10 digit random number in Visual Basic 2005

Posted on 2007-10-17
Medium Priority
Last Modified: 2013-11-27
How can I generate a random 10 digit number in Visual Basic 2005?

Thank you
Question by:OsirisJa
LVL 48

Accepted Solution

jpaulino earned 2000 total points
ID: 20095844
Try this

Dim num As New Random
Dim result As Long
For x As Byte = 0 To 9
  result &= num.Next(1,10)
Next x

MsgBox result

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 20096567
If you want the number 0 (zero) to be included then:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim num As Long = Long.Parse(RandomNumber(10))
    End Sub

    Private Function RandomNumber(ByVal length As Integer) As String
        Static R As New Random
        Dim num As String
        num = R.Next(1, 10) ' 1 to 9 for FIRST digit
        For i As Integer = 2 To length
            num &= R.Next(0, 10) ' 0 to 9 for subsequent digits
        Return num
    End Function

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question