Difference between revisions of "Not equal"

From Xojo Documentation

(Undo revision 49031 by PLefebvre (talk))
Line 3: Line 3:
 
|text = Used to determine whether one expression is not equal to another. [[String]] comparisons are case-insensitive. }}
 
|text = Used to determine whether one expression is not equal to another. [[String]] comparisons are case-insensitive. }}
  
 
+
== Usage ==
==Syntax==
+
result = expression1 <> expression2
result=expression1 <> expression2
 
 
{| class="genericTable"
 
{| class="genericTable"
  
Line 34: Line 33:
 
|}
 
|}
  
 
+
== Notes ==
==Notes==
 
 
The data types of expression1 and expression2 must match. You can make comparisons between objects of any data type and between objects. If you compare objects, '''<>''' compares their references, not their contents. For example, when you compare two [[FolderItem|FolderItems]], '''<>''' determines whether they have the same reference, not whether they point to the same file.
 
The data types of expression1 and expression2 must match. You can make comparisons between objects of any data type and between objects. If you compare objects, '''<>''' compares their references, not their contents. For example, when you compare two [[FolderItem|FolderItems]], '''<>''' determines whether they have the same reference, not whether they point to the same file.
  
Line 44: Line 42:
 
You can use [[Operator_Compare]] to define comparisons for classes.
 
You can use [[Operator_Compare]] to define comparisons for classes.
  
==Examples==
+
== Sample Code ==
The following example tests whether a [[FolderItem]] is [[Nil]] before assigning it to the Movie property of a [[MoviePlayer]] control.
+
Check if two string values are different:
  
 
<rbcode>
 
<rbcode>
Dim f As FolderItem
+
Dim t1 As String = "Hello"
f=GetOpenFolderItem("video/quicktime")
+
Dim t2 As String = "There"
If f<>Nil then
+
 
MoviePlayer1.movie=f.OpenAsMovie
+
If t1 <> t2 Then
End if
+
  // t1 is not equal to t2
 +
Else
 +
  // t1 is equal to t2
 +
End If
 
</rbcode>
 
</rbcode>
  
 
+
Test that an object is not Nil before it is used:
The following example uses '''&lt;&gt;''' to test for blank [[TextField|TextFields]].
 
 
 
 
<rbcode>
 
<rbcode>
Dim a,b as Integer
+
Dim d As New Dictionary
If TextField1.text <> "" and TextField2.text <> "" then
+
If d <> Nil Then
a=Val(TextField1.text)
+
  d.Value("Test") = "Hello"
b=Val(TextField.text)
+
End If
If a<b then
 
MsgBox "A is Less Than B!"
 
else
 
Beep
 
end if
 
else
 
MsgBox "Please enter values into both boxes!"
 
end if
 
 
</rbcode>
 
</rbcode>
  
==See Also==
+
== See Also ==
 
[[Greater_than|&gt;]], [[Greater_than_or_equal|&gt;=]], [[Less_than|&lt;]], [[Less_than_or_equal|&lt;=]], [[=]], and [[StrComp]] operators; [[Operator_Compare]] function; [[Operator_Precedence | Operator precedence]].
 
[[Greater_than|&gt;]], [[Greater_than_or_equal|&gt;=]], [[Less_than|&lt;]], [[Less_than_or_equal|&lt;=]], [[=]], and [[StrComp]] operators; [[Operator_Compare]] function; [[Operator_Precedence | Operator precedence]].
  
 
[[Category:Text_Strings]]
 
[[Category:Text_Strings]]

Revision as of 19:03, 11 June 2018

Operator

Used to determine whether one expression is not equal to another. String comparisons are case-insensitive.

Usage

result = expression1 <> expression2

Part Type Description
result Boolean Returns True if expression1 is not equal to expression2.
expression1 String, Number, Object, Color, or Date Any expression.
expression2 String, Number, Object, Color, or Date Any expression.

Notes

The data types of expression1 and expression2 must match. You can make comparisons between objects of any data type and between objects. If you compare objects, <> compares their references, not their contents. For example, when you compare two FolderItems, <> determines whether they have the same reference, not whether they point to the same file.

The <> operator is also used with objects to test whether they are Nil. For example, when you use the MemoryBlock constructor to create a new object, test whether the new object is Nil before proceeding.

Use StrComp to do a case-sensitive string comparison.

You can use Operator_Compare to define comparisons for classes.

Sample Code

Check if two string values are different:

Dim t1 As String = "Hello"
Dim t2 As String = "There"

If t1 <> t2 Then
// t1 is not equal to t2
Else
// t1 is equal to t2
End If

Test that an object is not Nil before it is used:

Dim d As New Dictionary
If d <> Nil Then
d.Value("Test") = "Hello"
End If

See Also

>, >=, <, <=, =, and StrComp operators; Operator_Compare function; Operator precedence.