If - Then - And

VB.NET 2005.

If I have the following IF statement:

If DirCheckFunc(DirPath1) and DirCheckFunc(DirPath2) Then
  -Do this
Else
 MsgBox ("Something Here")
End If

Basically, the DirCheckFunc is a function returning a True or False for each one DirPath1 and DirPath2.  In the MsgBox for the Else portion, I would like to identify the one that caused the statement to be False. How do or can I determine which one caused it to be false without having to check each one again.

Thanks
sneeri_cAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>the DirCheckFunc is a function returning a True or False

Dim bDirCheckFunc1 as Boolean
Dim bDirCheckFunc2 as Boolean

bDirCheckFunc1 = DirCheckFunc(DirPath1)
bDirCheckFunc2 = DirCheckFunc(DirPath2)

Select Case True
   Case bDirCheckFunc1  = True AND DirCheckFunc(DirPath2) = True
      - Both are True.  Do this
  Case bDirCheckFunc1  = True
      - Only DirPath1 is true
  Case bDirCheckFunc2  = True
      - Only DirPath2 is true  
  Case Else
      - Both are false.
      MsgBox ("Something Here")
End Select

Hope this helps.
-Jim
0
 
Ryan ChongCommented:
If DirCheckFunc(DirPath1) and DirCheckFunc(DirPath2) Then
  -Do this
Else
   if DirCheckFunc(DirPath1) = false then
         MsgBox ("DirPath1 is false")
   elseif DirCheckFunc(DirPath2) = false then
         MsgBox ("DirPath2 is false")
   end if
End If
0
 
lojk.Net and Infrastructure ConsultantCommented:
easy as this....

dim tResult1 as boolean=DirCheckFunc(DirPath1)
dim tResult2 as boolean =DirCheckFunc(DirPath2)
If tResult1 and tResult2 Then
  -Do this
Else
 MsgBox ("Result1 = " & result1 & vbcrlf & "Result2 = " & result2)
End If


oh, just realised this is basically what jimhorn said (although he does have a minor error)... ah well post anyway... ;-)
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.