Jump to content

Trying to display the contents of a random string generator into a label in vb.net

cab11150904

Figured it out.

should post your solution so people looking can find it.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

should post your solution so people looking can find it.

I'm not sure I can post that.  It's for my final project and you know how people feel about final solutions :D

 

 

The code for the RNG.  Change the 4 in the (Loop Until final.Length = 4) to whatever number of characters you need your randomly generated code to be.  

 

Public Function HomeID(ByRef lenStr As Integer, Optional ByVal upper As Boolean = False) As String
        Dim rand As New Random()
        Dim allowableChars() As Char = "abcdefghighlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray()
        Dim final As New System.Text.StringBuilder
        Do
            final.Append(allowableChars(rand.Next(0, allowableChars.Length)))
        Loop Until final.Length = 4
        Return If(upper, final.ToString.ToUpper(), final.ToString)
 
    End Function
 
 
The code to insert it into whatever you call your text box or label
 
    Private Sub btnRandom_Click(sender As Object, e As EventArgs) Handles btnRandom.Click
        lblRandom.Text = HomeID(4)
    End Sub
 
 
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×