Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VisualStudio2012
How can i check 4 things with one "If statement" and using for all the same msgbox...
 

here is the code: For VS2012 can't use and &&, or ||...What can i use?
 
If (Form2.txtName.Text ="" Form2.txtLastName.Text = "" Form2.cboField.Text = 0 Form2.cboStudy.Text = 0) Then
           MsgBox("Fill all your information please")
       End If
Posted 18-Jan-13 9:22am
San Dra391
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Sergey Alexandrovich Kryukov at 18-Jan-13 19:34pm
   
Right, a 5. Will OP understand the difference? "AndAlso" optimized out redundant check, but if condition calls some functions with side effect, such optimization will get this side effect lost, which can be a problem.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If you are writing in VB.NET, the keywords are
AndAlso
(equivalent to C# double ampersand) and
OrElse
(equivalent to C# double pipe).
 
If (Form2.txtName.Text ="" OrElse Form2.txtLastName.Text = "" OrElse Form2.cboField.Text = 0 OrElse Form2.cboStudy.Text = 0) Then
           MsgBox("Fill all your information please")
       End If
 
You should also use String.IsNullOrEmpty() to check if a string is null or an empty string ("").
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 18-Jan-13 19:34pm
   
Right, a 5. But will OP understand the difference? "AndAlso" optimized out redundant check, but if condition calls some functions with side effect, such optimization will get this side effect lost, which can be a problem.
—SA
San Dra at 19-Jan-13 6:52am
   
It worked with "OrElse"..so that's for Visual Studio 2012 in vb..:))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 470
1 mhegazy94 460
2 Ravi Bhavnani 190
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,135
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,619
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100