Wednesday, December 12, 2012

logical and relational operators of visual basic


Relational operators: Relational operators are used for comparison of to variables of same data type. These operators are used in the conditions where two values are compared and true or false is returned according to test result. Logical operators in VB are:
Equality (=)
Inequality(<>)
Less than(<)
Greater than(>)
Less than or equal to (<=)
Greater than or equal to(>=)

Example: 3 > 5 returns you false and 3 < 5 returns you true, which can be used in if statement.

Logical operators: Logical operators are used write a compound condition. You can use compound conditions to test more than one condition. Create compound condition by joining two conditions with Logical Operators. The Logical Operators are Or, And, Not, Imp, Xor,Eqv and like.
Example:
If optMale.Value = True And Val(txtAge.Text) < 21 Then
minMinorMaleCount = minMinorMaleCount + 1
End If