我从组合中获得价值。我要检查其选择的值是大于01还是小于05。
下面是我的示例
如果(cboPaymentMethod.SelectedItem.ToString.Substring(0,(cboPaymentMethod.SelectedItem).ToString.IndexOf(“-”))。ToString.Trim.ToUpper)>“ 01”和(cboPaymentMethod.SelectedItem.ToString.Substring (0,(cboPaymentMethod.SelectedItem).ToString.IndexOf(“-”))。ToString.Trim.ToUpper)<“ 05”然后
过程
如果结束
答案 0 :(得分:2)
通常最好将代码分成多个单独的部分,而不是一行全部完成。这样可以更轻松地查看正在发生的情况并避免冗余。
看起来您的想法正确,但是在所有混乱的地方可能存在问题,所以让我们这样重写它:
If cboPaymentMethod.SelectedIndex >= 0 Then
Dim itm = cboPaymentMethod.SelectedItem.ToString()
Dim dashPos = itm.IndexOf("-")
If dashPos >= 0 Then
Dim num = itm.Substring(0, dashPos).Trim()
If num > "01" AndAlso num < "05" Then
MsgBox("In range")
End If
End If
End If
MsgBox在那里只是为了快速测试。