难以理解为什么我得到" System.ArgumentOutOfRangeException"错误

时间:2015-05-19 15:14:08

标签: random visual-studio-2013

我遇到了一个问题,我的Visual Basic类程序让我感到难过。分配是一个猜测游戏,我创建一个私有子,在用户输入的边界内生成一个随机数(即...... 1 - 100)。我似乎有这个功能,除了告诉计算机猜测更低。目前,如果我按" Higher"游戏还在继续,但是如果我按下"降低"使用" minValue不能超过maxValue"抛出错误。如果文本框中的输出高于我的lownum变量,为什么我会收到此错误? 粗体代码是我写的代码,其他一切都是提供的。

Public Class frmGuess
Dim highNum As Integer
Dim lowNum As Integer
Dim guess As Integer

Private Sub frmGuess_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    MessageBox.Show("Lets Play a Game!")
    'Fixed the grammatical error below - "Think of an whole number" is incorrect.
    MessageBox.Show("Think of a whole number -- DON'T TELL ME!")
    MessageBox.Show("Now give me a range you want me to guess in... like 1 to 100.")
    lowNum = InputBox("Whats the starting value?", "Lowest Value")
    highNum = InputBox("Whats the ending value?", "Highest Value")
    lblTitle.Text = "I am guessing a number between " & lowNum & " and " & highNum & "."
    newGuess()
End Sub

**Sub newGuess()
    '
    '   ITS GONE! OH NO!
    '
    'New Guess Sub - Calculates a response based on the input from user and recalculates responses to guess the number.
    'Setting New Variables
    Dim random As New Random

    'Generating Response
    txtGuess.Clear()
    txtGuess.Text = random.Next(lowNum, highNum + 1)

End Sub**

Private Sub btnLower_Click(sender As Object, e As EventArgs) Handles btnLower.Click
    highNum = guess - 1
    newGuess()
End Sub

Private Sub btnHigher_Click(sender As Object, e As EventArgs) Handles btnHigher.Click
    lowNum = guess + 1
    newGuess()
End Sub

Private Sub btnCorrect_Click(sender As Object, e As EventArgs) Handles btnCorrect.Click
    MessageBox.Show("I win. I told you I was awesome.")
    Close()
End Sub

Private Sub txtGuess_TextChanged(sender As Object, e As EventArgs) Handles txtGuess.TextChanged

End Sub

结束班

1 个答案:

答案 0 :(得分:0)

想出来,程序按预期运行。