a said:
If then
If then
End if
End if
I don't understand this nested condition can you please give advice
information of how using this nested (if) and how it works and example
Thank you
Put simply, the inner if will only be evaluated if the outer if evaluates to
True.
If Dir("c:\temp\test.txt") <> "" Then
If UserWantsToDelete Then
Kill "c:\temp\test.txt"
End If
End If
What that does is check to see if the file "c:\temp\test.txt" exists. If it
does, a variable called UserWantsToDelete is checked to see if it's True. If
it is, the file is deleted.
The inner if is no good on its own, because when the file doesn't exist, the
kill statement will give a runtime error. So we enclose it in a check for
the file's existence.
Note that in order for the kill statement to execute, both conditions must
be True. This means that it could also be written this way:
If Dir("c:\temp\test.txt") <> "" And UserWantsToDelete Then
Kill "c:\temp\test.txt"
End If
or even (this is all one line despite how it looks here) :
If Dir("c:\temp\test.txt") <> "" And UserWantsToDelete Then Kill
"c:\temp\test.txt"
But the nested If blocks break up the code and make it easier to read, in my
opinion.
Hope that helps