If - Then - And

Posted on 2006-06-04
Last Modified: 2010-04-07
VB.NET 2005.

If I have the following IF statement:

If DirCheckFunc(DirPath1) and DirCheckFunc(DirPath2) Then
  -Do this
 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.

Question by:sneeri_c
    LVL 65

    Accepted Solution

    >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.
    LVL 48

    Expert Comment

    by:Ryan Chong
    If DirCheckFunc(DirPath1) and DirCheckFunc(DirPath2) Then
      -Do this
       if DirCheckFunc(DirPath1) = false then
             MsgBox ("DirPath1 is false")
       elseif DirCheckFunc(DirPath2) = false then
             MsgBox ("DirPath2 is false")
       end if
    End If
    LVL 9

    Expert Comment

    easy as this....

    dim tResult1 as boolean=DirCheckFunc(DirPath1)
    dim tResult2 as boolean =DirCheckFunc(DirPath2)
    If tResult1 and tResult2 Then
      -Do this
     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... ;-)
    LVL 65

    Expert Comment

    by:Jim Horn
    Thanks for the grade.  Good luck with your project.  -Jim

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now