.net 大于,小于,带负数

.net 大于,小于,带负数,.net,vb.net,.net,Vb.net,您好,我在vb.net中使用大于小于函数时遇到问题。它完美地适用于正数,但不适用于负数。这是我的代码,我希望这有帮助 Dim A, B, input As Integer A = (-38) B = (-173) txtD.Text = CStr(CInt(txtD.Text)) input = CInt(txtD.Text) If input <= 32 < CInt(A) Then txtR.Text = "Water will freeze and Oxygen wi

您好,我在vb.net中使用大于小于函数时遇到问题。它完美地适用于正数,但不适用于负数。这是我的代码,我希望这有帮助

Dim A, B, input As Integer
A = (-38)
B = (-173)
txtD.Text = CStr(CInt(txtD.Text))
input = CInt(txtD.Text)

If input <= 32 < CInt(A) Then
    txtR.Text = "Water will freeze and Oxygen will boil at this Temperature"
ElseIf input <= CInt(A) > CInt(B) Then
    txtR.Text = "Water and Mercury will Freeze and Oxygen will boil at this temperature"
End If
尺寸A、B,输入为整数
A=(-38)
B=(-173)
txtD.Text=CStr(CInt(txtD.Text))
输入=CInt(txtD.Text)

如果输入不幸,您的代码语法错误:

If input <= 32 < CInt(A) Then
     txtR.Text = "Water will freeze and Oxygen will boil at this Temperature"
ElseIf input <= CInt(A) > CInt(B) Then
     txtR.Text = "Water and Mercury will Freeze and Oxygen will boil at this temperature"
End If
但是,根据变量
A
B
的设置,这些值不会计算为真

作为补充说明:

txtD.Text = CStr(CInt(txtD.Text))
这是一句毫无意义的话

txtD.Text
返回一个字符串,因此无需先将其转换为整数,再转换为字符串,然后将其分配给自身。简单地删除这个


另外,
A
B
已经是整数,您不必使用
CInt
将它们转换为整数。只需直接使用变量
A
B

您需要
加入您的条件

差不多

     If input <= 32 And 32 < CInt(A) Then
          txtR.Text = "Water will freeze and Oxygen ..."
     ElseIf input <= CInt(A) And  CInt(A) > CInt(B) Then
          txtR.Text = "Water and Mercury will Freeze and Oxygen will ..."
     End If

如果您没有给出输入示例、预期结果和实际结果。我个人还建议一次只表达一个条件,并使用
(或其他什么)将它们结合起来-我(作为一个简单的C#开发者)不清楚
输入CInt(B)
是如何计算的。(也不清楚为什么要使用
CInt(a)
CInt(B)
当它们已经是整数时。)请注意,如果启用了
选项Strict
,则可能会因为代码问题而收到错误消息。我强烈建议您开始使用
Option Strict
…我觉得这将是一个很好的时机,可以让新手使用“AndAlso”而不是“And”,以避免VB.Net中常见的陷阱。你怎么认为?
     If input <= 32 And 32 < CInt(A) Then
          txtR.Text = "Water will freeze and Oxygen ..."
     ElseIf input <= CInt(A) And  CInt(A) > CInt(B) Then
          txtR.Text = "Water and Mercury will Freeze and Oxygen will ..."
     End If