Logical Operators in VB.NET
How to use the logical operators in VB.NET?
Explanation
Logical Operators
Logical Operators are used to compare Boolean expressions to return the result as a Boolean value.
Following table lists the Logical Operators used in Visual Basic.net 2008.
Operator |
Description |
And |
Both Conditions must be true |
or |
Either one condition is true |
Xor |
One condition can be true, but not both |
Not |
None should be true |
Example:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
If ((Val(TextBox1.Text) > 10) And (Val(TextBox1.Text) < 20))
Then
MsgBox("Date is in the Middle of the Month")
ElseIf ((Val(TextBox1.Text) < 1) Or (Val(TextBox1.Text) > 31))
Then
MsgBox("Enter a Valid Date")
Else
MsgBox("Date entered is either is in Start or End of Month")
End If
End Sub
End Class
Explanation:
In the above example we have used
And operator to check the value entered in the
TextBox1
is from middle of the month.
Or operator is used to find the invalid entry.