Comparison Operators in VB.NET
List of Comparison Operators in VB.NET
Explanation
Comparison Operators in VB.NET
Comparison Operators are used to compare two expressions to return a result which will be a Boolean value.
Following table lists the Comparison Operators used in Visual Basic.
Operator |
Description |
< |
Less than |
<= |
Less than or equal to |
> |
Greater than |
>= |
Greater than or equal to |
= |
Equal to |
<> |
Not equals |
Example:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
If a > b Then
MsgBox("A is greater than B")
ElseIf a < b Then
MsgBox("A is Less than B")
ElseIf a = b Then
MsgBox("A is equal to B")
Else
MsgBox("Enter Valid Numbers")
End If
End Sub
End Class
Description:
In the above example, the values got using the
TextBox1 and
TextBox2 are compared using the
logical comparison operators
>,<,= using a if..elseif loop.