We help IT Professionals succeed at work.
Get Started

Generate a random password with only 1 number

Last Modified: 2010-04-23
I need to generate a 6 digit password that contains all caps and one number.  I am using this code, but not sure how to get it to only give one number.  I have it setup to not include confusing numbers/letters such as O,0,i,l, ect.  I also have it only give me 5 characters instead of 6 sometimes  (not sure why it does that).  What am I missing?  Thanks, Chad

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call GetRndPass()
    End Sub
    Public Sub GetRndPass()
        Dim sAlpha As String
        Dim sNumeric As String
        Dim sResult As String
        Dim bDone As Boolean
        Dim i As Integer
        sNumeric = "23456789"
        bDone = True
        Do While bDone
            Select Case Int(Rnd() * 2) + 1
                Case 1
                    sResult = sResult & Mid(sAlpha, CStr(Rnd() * 19) + 1, 1)
                Case 2
                    sResult = sResult & Mid(sNumeric, Int(Rnd() * i) + 1, 1)
            End Select
            i = i + 1
            If i = 6 Then
                bDone = False
            End If
    End Sub
End Class
Watch Question
Top Expert 2007
This problem has been solved!
Unlock 1 Answer and 15 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE