Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vb.Net中的If-Else语句_Vb.net_If Statement - Fatal编程技术网

vb.Net中的If-Else语句

vb.Net中的If-Else语句,vb.net,if-statement,Vb.net,If Statement,我想让这个条件像b2.text、c3.text、d4.text、e5.text、f6.text、g7.text、h8.text、i9.text和j10.text一样 若它们都等于零,那个么其他语句继续 我试过了 If (b2.Text = 0 & c3.Text = 0 & d4.Text = 0 & e5.Text = 0 & f6.Text = 0 & g7.Text = 0 & h8.Text = 0 & i9.Text = 0 &a

我想让这个条件像b2.text、c3.text、d4.text、e5.text、f6.text、g7.text、h8.text、i9.text和j10.text一样

若它们都等于零,那个么其他语句继续

我试过了

If (b2.Text = 0 & c3.Text = 0 & d4.Text = 0 & e5.Text = 0 & f6.Text = 0 & g7.Text = 0 & h8.Text = 0 & i9.Text = 0 & j10.Text = 0) Then
            a1.Text = 10000000

        Else


Msgbox.Show("Cannot sort")
End if
不幸的是,我记得&函数只接受两个变量:p

我怎么做?
谢谢

我不知道您使用的是什么语言,但我非常确定您可以比较两个以上的值。解决方案可能是这样的

if (b2.text == 0 && c3.text == 0 && d4.text == 0 && e5.text== 0 && f6.text == 0 && g7.text == 0 && h8.text == 0 && i9.text == 0 && j10.text == 0) {
    //  when conditions are true
}
else {
   // else code here
} 

你不需要&对于VB,你需要AndAlso。虽然它可能比您的级别高一点,但您可能希望了解Linq

If ({b2.Text, c3.Text, d4.Text, e5.Text, f6.Text, g7.Text, h8.Text, i9.Text, j10.Text}).All(Function(f) f = "0") Then
    a1.Text = 10000000
Else
   Msgbox.Show("Cannot sort")
End IF

正如其他人所说,您应该启用Option Strict,以便标记与int的比较。我在上面创建了字符串0,但如果您实际需要长度,您可以轻松修改它以使用长度。

您可以分享您的尝试吗?你分享的东西实际上并不是编码?你忘记了圆括号,也忘记了应该设置的双符号和可能的重复符号-它会为你指出一些问题。另外,你的意思是文本框是空的吗?你的意思是它们包含字符串0吗?我正在使用VB.NET:我忘了添加它sorry@AndrewMorton:是的,我考虑过这一点,但认为更改越少越好,特别是因为有些值可能不是来自控件-希望他实际上没有将控件命名为a,b和c。