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
Medium Priority
211 Views
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
Question by:sneeri_c
• 2

LVL 66

Accepted Solution

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

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

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

ID: 16867417
0

## Featured Post

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
Course of the Month14 days, left to enroll