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
- MsgBox("Welcome joken!")
- '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:
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.
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.