Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

If - Then - And

Posted on 2006-06-04
4
Medium Priority
?
211 Views
Last Modified: 2010-04-07
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
0
Comment
Question by:sneeri_c
  • 2
4 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 1000 total points
ID: 16829155
>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
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 16829695
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
 
LVL 9

Expert Comment

by:lojk
ID: 16841204
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
 
LVL 66

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

581 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