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