视觉基础等于或大于

时间:2012-11-30 03:25:12

标签: vb.net

我正在尝试编写一些代码,说明如果textbox1在10之间等于0,则HandDecimal = 1.否则如果textbox1等于10.1到100,则HandDecimal = 3.否则textbox1等于100.1且大于HandDecimal = 5.

这是我的代码,但它似乎对我不起作用。

        If WeightDecimal = 0 <= 10 Then

            HandDecimal = 1

        ElseIf WeightTextBox.Text = 10 <= 100 Then

            HandDecimal = 3

        ElseIf WeightTextBox.Text >= 100.1 Then

            HandDecimal = 5

        End If

如何更改代码才能使其正常工作?

2 个答案:

答案 0 :(得分:7)

   Dim weight as Decimal = Decimal.Parse(WeightTextBox.Text) 
   If weight  >= 0 AndAlso weight <= 10 Then

        HandDecimal = 1

    ElseIf weight  > 10 AndAlso weight <= 100 Then

        HandDecimal = 3

    ElseIf weight > 100 Then

        HandDecimal = 5

    End If

答案 1 :(得分:4)

Select Case运算符

To语句

Select Case WeightDecimal
Case 0 To 10
    HandDecimal = 1
Case 10.1 To 100
    HandDecimal = 3
Case Else 
    HandDecimal = 5
End Select