nfell2009

Randomly Number Generator

Dec 10th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.40 KB | None | 0 0
  1. Public Class Form1
  2.     'Code by Nicholas Fell
  3.  
  4.     Dim iPrev As Integer = 0 'Will be set after each random, needs a value to start with to prevent repeats
  5.     Dim iNumber As Integer 'This will have numbers put into it
  6.     Dim sItoS As String 'A string to have the converted iNumber put into
  7.     Private Sub btnRandom_Click(sender As Object, e As EventArgs) Handles btnRandom.Click
  8.         Random() 'Calling the procedure
  9.     End Sub
  10.  
  11.     Public Sub Random()
  12.         iNumber = Int(Rnd() * 5 + 1) 'Randomly creating a number between 1-5
  13.  
  14.         If iNumber = iPrev Then 'Checks for the currently generated number and the previous number
  15.             Random() 'The 2 numbers match, so the procedure will be done again until there is no match
  16.         Else 'Happens if no match is found
  17.             txtOutput.Text = iNumber 'Setting the textbox to the generated number
  18.             iPrev = iNumber 'Gives iPrev a value, this will be used next time a random is used to stop repeates
  19.  
  20.             'FOLLOWING LINES AREN'T NEEDED! THEY ARE FOR RECORDING THE NUMBER INTO A RICHTEXTBOX! IF YOU USE STRINGS THIS ISN'T NEEDED EITHER
  21.             sItoS = Convert.ToString(iNumber) 'Converts the iNumber integer into a string
  22.  
  23.             rtbList.Text = rtbList.Text + sItoS + vbNewLine 'Adds the newly converted string to the richtextbox
  24.         End If 'Ends the if function
  25.     End Sub 'Ends the random procedure
  26. End Class
Advertisement
Add Comment
Please, Sign In to add comment