w000t Grand Master Joined Jan 23, 2007 Sythe Gold 0 Messages 2,608 Location GFX section. Feb 5, 2011 #1 Well I've begun working on my first VB.net program its a password genorator all it does is generates a random sequence for a password and i cant seem to figure out how to get it to generate random numbers and letters. Any help is appreciated.
Well I've begun working on my first VB.net program its a password genorator all it does is generates a random sequence for a password and i cant seem to figure out how to get it to generate random numbers and letters. Any help is appreciated.
N NullzHost Newcomer Joined Feb 5, 2011 Sythe Gold 0 Messages 4 Feb 5, 2011 #2 First implment this code in your form: Code: Private Function RandomNumberAsString(ByVal Min As Int32, ByVal Max As Int32) As String Return (New Random).Next(Min, Max).ToString End Function Then when a user clicks Button1 or whatever put this code for it. Code: TextBox1.Text = Me.RandomNumberAsString(1000, 999999) This will randomly generate a number between 1000 and 999999, change it as needed.
First implment this code in your form: Code: Private Function RandomNumberAsString(ByVal Min As Int32, ByVal Max As Int32) As String Return (New Random).Next(Min, Max).ToString End Function Then when a user clicks Button1 or whatever put this code for it. Code: TextBox1.Text = Me.RandomNumberAsString(1000, 999999) This will randomly generate a number between 1000 and 999999, change it as needed.
S SLiZZaRD Active Member Joined Feb 4, 2011 Sythe Gold 0 Messages 230 Location Australia Feb 10, 2011 #3 Public Function Gen_Rand_Password(PassLength As Integer) As String Dim RetVal As String Dim Max As Integer Dim Min As Integer Max = 126 Min = 48 Randomize Timer If PassLength < 8 Then Gen_Rand_Password = "error: invalid length" End If For I = 1 To PassLength RetVal = RetVal & Chr(Int((Max - Min + 1) * Rnd + Min)) Next I Gen_Rand_Password = RetVal End Function RandomPassword = Gen_Rand_Password(8) Click to expand... Code is set to the standard length of eight. Shoot me a PM if you're unable to apply. If your not 100% with you "for loops" then look at this tutorial: http://www.youtube.com/watch?v=aM_5FWRk23c It's fairly basic but you get the idea.
Public Function Gen_Rand_Password(PassLength As Integer) As String Dim RetVal As String Dim Max As Integer Dim Min As Integer Max = 126 Min = 48 Randomize Timer If PassLength < 8 Then Gen_Rand_Password = "error: invalid length" End If For I = 1 To PassLength RetVal = RetVal & Chr(Int((Max - Min + 1) * Rnd + Min)) Next I Gen_Rand_Password = RetVal End Function RandomPassword = Gen_Rand_Password(8) Click to expand... Code is set to the standard length of eight. Shoot me a PM if you're unable to apply. If your not 100% with you "for loops" then look at this tutorial: http://www.youtube.com/watch?v=aM_5FWRk23c It's fairly basic but you get the idea.