-4

I wanted to have this condition like i have b2.text, c3.text, d4.text, e5.text, f6.text, g7.text, h8.text, i9.text and j10.text.

And if they are all equal to zero then statement else continue.

i tried

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

Unfortunately i remembered & function only accept two variable only :P

How can i do it? Thank you

2 Answers2

0

You don't want & for VB, you want AndAlso. And while it is probably a bit above your level, you might want to look into 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

As others have said, you should turn on Option Strict, so that your comparison to an int gets flagged. I made the string "0" above, but you could easily modify it to use length if that is what you actually need.

jmoreno
  • 12,752
  • 4
  • 60
  • 91
  • 1
    @AndrewMorton: yes, I thought about that, but decided fewer changes were better, particularly since it's possible that some of the values might not come from controls -- hopefully he doesn't actually name controls a,b and c. – jmoreno Oct 19 '15 at 13:35
-1

I don't know what language are you using but I'm pretty sure you can compare more than 2 values The solution may be like this.

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
} 
Ryan Vincent
  • 4,483
  • 7
  • 22
  • 31
ssg
  • 129
  • 7