计算应该计算的事情 [英] Calculating things that doenst supposed to be calculated
问题描述
你好,
我正在制作一个必须计算立方体体积的程序。每个边的输入数字必须大于0且小于100,但是当我输入101时,它仍然计算它。我不知道是什么导致了这个问题,所以这就是为什么我要
问你们。这是代码:
I'm making a program which has to calculate the volume of a cube. The entered number for each of the side has to be greater than 0 and lower than 100 but when I enter 101 it still calculates it. I dont know what causes this problem, so thats why I have to ask you guys. This is the code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If IsNumeric(TextBox1.Text) And 0 < IsNumeric(TextBox1.Text) < 99 Then
Label3.Text = TextBox1.Text ^ 3
Label4.Text = "Possible Errors"
Label4.BackColor = Color.Maroon
ElseIf IsNumeric(TextBox1.Text) < 0 Then
Label4.Text = "insert a number between 0 and 9"
Label4.BackColor = Color.Red
Label3.Text = "Uitkomst"
ElseIf IsNumeric(TextBox1.Text) > 99 Then
Label4.Text = "insert a number between 0 and 9"
Label4.BackColor = Color.Red
Label3.Text = "Uitkomst"
End If
If Not IsNumeric(TextBox1.Text) Then
Label3.Text = "Uitkomst"
Label4.Text = "use numbers!"
Label4.BackColor = Color.Red
End If
End Sub
End Class
如果可以帮助我,我非常感谢您的想法和解决方案
If you can help me, I would really appreciate your ideas and solutions
提前致谢,
Justin
推荐答案
问候贾斯汀。
VB不是我的语言,但是没有其他人发布回复,我以为我会去。
VB isn't my language, but as nobody else has posted a reply I thought I would have a go.
问题几乎可以肯定是因为IsNumeric返回bool而不是数字。因此这一行......
The problem is almost certainly because IsNumeric returns a bool, not a number. Thus this line...
If IsNumeric(TextBox1.Text) And 0 < IsNumeric(TextBox1.Text) < 99 Then
...如果TextBox1.Text是数字,将始终为true,无论数量是多少。您需要的代码如下所示(记住,我不熟悉VB,所以这可能是完全错误的,但我希望它会给你这个想法)。
... will always be true if TextBox1.Text is numeric, no matter what the number is. The code you need is something like the following (remember, I'm not fluent in VB, so this could be completely wrong, but I hope it will give you the idea).
Dim number As Integer = -1;
If IsNumeric(TextBox.Text) Then
number = Convert.ToInt32(TextBox.Text, 16)
End If
If (0 < number < 99) Then
Label3.Text = TextBox1.Text ^ 3
Label4.Text = "Possible Errors"
Label4.BackColor = Color.Maroon
' And so on.
这篇关于计算应该计算的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!