Ok, I am making a simple Random Number Generator in VB.NET. Now, I am generating the numbers with this code:
Dim randomgenerator As New Random
Dim randomint As Integer = randomgenerator.Next(1, 8)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim randomint As Integer = randomgenerator.Next(1, 8)
textbox2.Text = randomgenerator.Next
input = TextBox1.Text
If input = "1" Then
one()
ElseIf input = "2" Then
two()
ElseIf input = "3" Then
three()
ElseIf input = "4" Then
four()
ElseIf input = "5" Then
five()
ElseIf input = "6" Then
six()
ElseIf input = "7" Then
seven()
ElseIf input = "8" Then
eight()
ElseIf input = "9" Then
nine()
End If
End Sub
Private Sub two()
Dim randomint As Integer = randomgenerator.Next(1, 8)
randomint = randomgenerator.Next(9, 99)
textbox2.Text = randomint
End Sub
Private Sub three()
Dim randomint As Integer = randomgenerator.Next(1, 8)
randomint = randomgenerator.Next(99, 999)
textbox2.Text = randomint
End Sub
Private Sub four()
Dim randomint As Integer = randomgenerator.Next(1, 8)
randomint = randomgenerator.Next(999, 9999)
textbox2.Text = randomint
End Sub
And so on and so fourth. Now, the problem is, when I get to;
Private Sub nine()
Dim randomint As Integer = randomgenerator.Next(1, 8)
randomint = randomgenerator.Next(99999999, 999999999)
textbox2.Text = randomint
End Sub
And try to go on to ten, and add one more digit to max and min value, it won't let me, giving a "Constand Expression not representable in type Integer"
How can I get around this to generate random numbers larger than 9?
Question
Patrick_
Ok, I am making a simple Random Number Generator in VB.NET. Now, I am generating the numbers with this code:
And so on and so fourth. Now, the problem is, when I get to;
And try to go on to ten, and add one more digit to max and min value, it won't let me, giving a "Constand Expression not representable in type Integer"
How can I get around this to generate random numbers larger than 9?
Thanks!
Link to comment
Share on other sites
4 answers to this question
Recommended Posts