Difference between revisions of "="

From Xojo Documentation

(See Also)
 
(Changed deprecated StrComp to String.Compare.)
 
(28 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 +
{{OperatorBox}}
 +
{{Description
 +
|text=The = character is to determine whether one expression is equal to another or to assign a value to a property or variable. [[String|String]] comparisons are case-insensitive.
 +
}}
  
 
+
== Usage ==
=='''Description'''==
+
''result'' = ''expression1'' = ''expression2''
Used to determine whether one expression is equal to another or to assign a value to a property or variable. [[String|String]] comparisons are case-insensitive.
+
{| cellpadding="6" cellspacing="0" border="1"  
 
+
! width=15%  style="background-color:#e0e0e0" | Part
 
+
! width=25%  style="background-color:#e0e0e0" | Type
 
 
=='''Syntax'''==
 
result=expression1 = expression2
 
{| cellpadding="8" cellspacing="0" border="1"  
 
 
 
! width=25%  style="background-color:#e0e0e0" | Part
 
 
 
! width=15%  style="background-color:#e0e0e0" | Type
 
 
 
 
! width=55%  style="background-color:#e0e0e0" | Description
 
! width=55%  style="background-color:#e0e0e0" | Description
 
|-
 
|-
 
|result
 
|result
 
 
|[[Boolean|Boolean]]
 
|[[Boolean|Boolean]]
 
|Returns [[True|True]] if ''expression1'' is equal to ''expression2''.
 
|Returns [[True|True]] if ''expression1'' is equal to ''expression2''.
 
 
|-
 
|-
 
|expression1
 
|expression1
 
 
|[[String|String]], Number, [[Boolean|Boolean]], [[Color|Color]], or [[Object|Object]]
 
|[[String|String]], Number, [[Boolean|Boolean]], [[Color|Color]], or [[Object|Object]]
 
|Any expression.
 
|Any expression.
 
 
|-
 
|-
 
|expression2
 
|expression2
 
 
|[[String|String]], Number, [[Boolean|Boolean]], [[Color|Color]] or [[Object|Object]]
 
|[[String|String]], Number, [[Boolean|Boolean]], [[Color|Color]] or [[Object|Object]]
 
|Any expression.
 
|Any expression.
 
 
|-
 
|-
 
|}
 
|}
'''result'''='''value'''
+
''result''=''value''
{| cellpadding="8" cellspacing="0" border="1"  
+
{| cellpadding="6" cellspacing="0" border="1"  
 
+
! width=15%  style="background-color:#e0e0e0" | Part
! width=25%  style="background-color:#e0e0e0" | Part
+
! width=25%  style="background-color:#e0e0e0" | Type
 
 
! width=15%  style="background-color:#e0e0e0" | Type
 
 
 
 
! width=55%  style="background-color:#e0e0e0" | Description
 
! width=55%  style="background-color:#e0e0e0" | Description
 
|-
 
|-
 
|result
 
|result
 
 
|Any
 
|Any
 
 
|The property, variable, array, or array element that is assigned ''value''.
 
|The property, variable, array, or array element that is assigned ''value''.
 
 
|-
 
|-
 
|value
 
|value
 
 
|Any
 
|Any
 
 
|The value assigned to result.
 
|The value assigned to result.
 
 
|-
 
|-
 
|}
 
|}
  
 +
== 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.
  
=='''Notes'''==
+
Use [[String.Compare]] to do a case-sensitive [[String|string]] comparison.  
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.
 
 
 
Use [[StrComp|StrComp]] to do a case-sensitive [[String|string]] comparison.  
 
  
 
You can use [[Operator_Compare|Operator_Compare]] to define comparisons for classes.
 
You can use [[Operator_Compare|Operator_Compare]] to define comparisons for classes.
  
 +
== Sample Code ==
 +
The following example tests whether two strings are equal.
  
 +
<rbcode>
 +
Var t1 As String = "Hello"
 +
Var t2 As String = "There"
  
=='''Examples'''==
+
If t1 = t2 Then
The following example tests whether two strings are equal.
+
  // t1 is equal to t2
<div style="background-color:#d0d0d0; padding-left:30px">[[Dim|Dim]] a,b as [[String|String]]<br /></div>
+
Else
<div style="background-color:#d0d0d0; padding-left:30px">[[If|If]] [[TextField|TextField1]].text &lt;&gt; "" and [[TextField|TextField2]].text &lt;&gt; "" then
+
  // t1 is not equal to t2
<br /></div>
+
End If
<div style="background-color:#d0d0d0; padding-left:30px">&#xA0;a=[[TextField|TextField1]].text
+
</rbcode>
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">&#xA0;b=[[TextField|TextField2]].text
 
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">[[If|If]] a'''='''b then
 
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">[[MsgBox|MsgBox]] "A is equal to B!"
 
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">&#xA0;else
 
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">[[Beep|Beep]]<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">end if
 
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px"> else
 
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">[[MsgBox|MsgBox]] "Please enter values into both boxes!"
 
<br /></div>
 
<div style="background-color:#d0d0d0; padding-left:30px">end if
 
<br /></div>
 
 
 
=='''See Also'''==
 
[[Greater_than|&gt;]], [[Greater_than=|&gt;=]], [[Less_than|&lt;]], [[Less_than=|&lt;=]], [[Not_Equal|&lt;&gt;]], and [[StrComp|StrComp]] operators; [[Operator_Compare|Operator_Compare]] function; [[Operator|Operator]] precedence.
 
  
 +
== See Also ==
 +
[[Equals]], [[Greater_than|&gt;]], [[Greater_than=|&gt;=]], [[Less_than|&lt;]], [[Less_than=|&lt;=]], [[Not_equal|&lt;&gt;]] operators; [[Operator_Compare|Operator_Compare]], [[String.Compare]] functions; [[Operator_Precedence |Operator precedence]].
  
[[Category:Operators]]
+
[[Category:Text_Strings]]
[[Category:Strings]]
 

Latest revision as of 14:16, 26 January 2021

Operator

The = character is to determine whether one expression is equal to another or to assign a value to a property or variable. String comparisons are case-insensitive.

Usage

result = expression1 = expression2

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

result=value

Part Type Description
result Any The property, variable, array, or array element that is assigned value.
value Any The value assigned to result.

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.

Use String.Compare to do a case-sensitive string comparison.

You can use Operator_Compare to define comparisons for classes.

Sample Code

The following example tests whether two strings are equal.

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

If t1 = t2 Then
// t1 is equal to t2
Else
// t1 is not equal to t2
End If

See Also

Equals, >, >=, <, <=, <> operators; Operator_Compare, String.Compare functions; Operator precedence.