In Visual Basic, we are using Conditional Operators to evaluate a condition that applied to one or two boolean expressions. An expression returning a value if the that expression is true and a different one if the expression is evaluated as false. The logical AND and OR operators both take two operands. Each operand is a boolean expression. It evaluates to either true or false.
The && (logical AND) operator indicates whether both operands are true then it returns true, otherwise it returns false.
Evaluating of Logical AND operators through expressions.
Expression Results
1 && 1 True or 1
1 && 0 False or 0
0 && 1 False or 0
0 && 0 False or 0
Visual Basic Code:
'declare a variable
Dim username As String
Dim password As String
'assign value to a variable
username = "joken"
password = "12345"
'test if the two expression match, then it welcome the user
If username = "joken" And password = "12345" Then
'returns true
Else
'return false
MsgBox("Username and Password did not match!") End If
The || (logical OR) operator indicates whether either operand is true, it returns true.
Evaluating of Logical OR operators through expressions.
Expression Results
1 && 1 True or 1
1 && 0 True or 1
0 && 1 True or 1
0 && 0 False or 0
Visual Basic Code:
'declare a string variable
Dim name As String
'assign value to a string variable
name = "Joken"
'test if name either of the two expression is true
If name = "Joken" Or name = "joken" Then
'return true
Else
'return false
MsgBox("Your not identified!") End If
In above example example is applicable in real-world application, especially when you are doing the login- logout system or any other application that need to passed through conditional operations.