Difference between revisions of "Operator ModuloRight"

From Xojo Documentation

m (1 revision)
 
m
 
(19 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 +
{{DISPLAYTITLE:Operator_ModuloRight}}{{MethodBox
 +
| name = Operator_ModuloRight
 +
}}
 +
{{Description
 +
|text = Used to overload the [[Mod]] function, providing custom functionality.}}
  
 +
== Notes ==
 +
Create an '''Operator_ModuloRight '''function in a class to specify the functionality of the [[Mod]] operator for that class. The instance of [[Self]] is on the right side of the [[Mod]] expression. The other instance is passed as a parameter.
  
=='''Description'''==
+
The ordinary (left) methods are always preferred; the Right version is used only if there is no legal left version.
Used to overload the [[Mod|Mod]] function, providing custom functionality.
 
  
 +
== Sample Code ==
 +
Using the Vector class (see [[Operator_Add]]) with two [[Integer]] elements, x and y, we define an '''Operator_ModuloRight''' function that returns the remainder of the division of the sum of the Self instance by the passed instance.
  
 +
<rbcode>
 +
Function Operator_ModuloRight(lhs As Vector) As Integer
 +
  Var a, b As Integer
 +
  a = Self.x + Self.y
 +
  b = lhs.x + lhs.y
  
=='''Notes'''==
+
  Return b Mod a
Create an '''Operator_ModuloRight '''function in a class to specify the functionality of the [[Mod|Mod]] operator for that class. The instance of [[Self|Self]] is on the right side of the [[Mod|Mod]] expression. The other instance is passed as a parameter.
+
End Function
 +
</rbcode>
  
The ordinary (left) methods are always preferred; REALbasic uses the Right version only if there is no legal left version.
+
== See Also ==
 +
[[Mod]] operator; [[Operator_Modulo]] function.
  
 
+
[[Category:Language_Operators]]
 
+
[[Category:Language Reference Index]]
=='''Examples'''==
 
Using the Vector class (see [[Operator_Add|Operator_Add]]) with two [[Integer|Integer]] elements, x and y, we define an '''Operator_ModuloRight''' function that returns the remainder of the division of the sum of the Self instance by the passed instance.
 
{| cellpadding="8" cellspacing="0" border="1"
 
|<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Function|Function]] '''Operator_ModuloRight''' (lhs as Vector) as [[Integer|Integer]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Dim|Dim]] a, b as [[Integer|Integer]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">&#xA0;a=[[Self|Self]].x + [[Self|Self]].y
 
<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">&#xA0;b=lhs.x + lhs.y
 
<br /></div>
 
<br />
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Return|Return]] b [[Mod|Mod]] a
 
<br /></div>
 
 
 
|-
 
|}
 
 
 
 
 
=='''See Also'''==
 
[[Mod|Mod]] operator; [[Operator_Modulo|Operator_Modulo]] function.
 
 
 
 
 
[[Category:Operators]]
 

Latest revision as of 08:18, 22 August 2021

Method

Used to overload the Mod function, providing custom functionality.

Notes

Create an Operator_ModuloRight function in a class to specify the functionality of the Mod operator for that class. The instance of Self is on the right side of the Mod expression. The other instance is passed as a parameter.

The ordinary (left) methods are always preferred; the Right version is used only if there is no legal left version.

Sample Code

Using the Vector class (see Operator_Add) with two Integer elements, x and y, we define an Operator_ModuloRight function that returns the remainder of the division of the sum of the Self instance by the passed instance.

Function Operator_ModuloRight(lhs As Vector) As Integer
Var a, b As Integer
a = Self.x + Self.y
b = lhs.x + lhs.y

Return b Mod a
End Function

See Also

Mod operator; Operator_Modulo function.