[192] | 1 | ' com/currency.ab
|
---|
| 2 |
|
---|
[200] | 3 | #require <com/variant.ab>
|
---|
| 4 |
|
---|
| 5 | #ifndef _COM_CURRENCY_AB
|
---|
| 6 | #define _COM_CURRENCY_AB
|
---|
| 7 |
|
---|
[192] | 8 | Class Currency
|
---|
| 9 | Public
|
---|
[211] | 10 | Sub Currency()
|
---|
| 11 | cy = 0
|
---|
| 12 | End Sub
|
---|
| 13 |
|
---|
[200] | 14 | /*
|
---|
| 15 | Sub Currency(x As CY)
|
---|
| 16 | cy = x
|
---|
| 17 | End Sub
|
---|
| 18 | */
|
---|
| 19 | Sub Currency(x As Double)
|
---|
| 20 | VarCyFromR8(x, cy)
|
---|
| 21 | End Sub
|
---|
| 22 | /*
|
---|
| 23 | Sub Currency(x As Int64)
|
---|
| 24 | VarCyFromI8(x, cy)
|
---|
| 25 | End Sub
|
---|
| 26 | */
|
---|
[192] | 27 | Const Function Operator +() As Currency
|
---|
| 28 | Return New Currency(This)
|
---|
| 29 | End Function
|
---|
| 30 |
|
---|
| 31 | Const Function Operator -() As Currency
|
---|
| 32 | Dim ret = New Currency
|
---|
| 33 | VarCyNeg(This.cy, ret.cy)
|
---|
| 34 | Return ret
|
---|
| 35 | End Function
|
---|
| 36 |
|
---|
| 37 | Const Function Operator *(y As Currency) As Currency
|
---|
| 38 | Dim ret = New Currency
|
---|
| 39 | VarCyMul(This.cy, y.cy, ret.cy)
|
---|
| 40 | Return ret
|
---|
| 41 | End Function
|
---|
| 42 |
|
---|
| 43 | Const Function Operator *(y As Long) As Currency
|
---|
| 44 | Dim ret = New Currency
|
---|
| 45 | VarCyMulI4(This.cy, y, ret.cy)
|
---|
| 46 | Return ret
|
---|
| 47 | End Function
|
---|
| 48 |
|
---|
| 49 | Const Function Operator *(y As Int64) As Currency
|
---|
| 50 | Dim ret = New Currency
|
---|
| 51 | VarCyMulI8(This.cy, y, ret.cy)
|
---|
| 52 | Return ret
|
---|
| 53 | End Function
|
---|
| 54 |
|
---|
| 55 | Const Function Operator /(y As Variant) As Double
|
---|
| 56 | Dim vx = New Variant(This)
|
---|
| 57 | Dim ret= vx / y
|
---|
| 58 | Return ret.ValR4
|
---|
| 59 | End Function
|
---|
| 60 |
|
---|
| 61 | Const Function Operator /(y As Currency) As Double
|
---|
| 62 | Return This / New Varinat(y)
|
---|
| 63 | End Function
|
---|
| 64 |
|
---|
| 65 | Const Function Operator +(y As Currency) As Currency
|
---|
| 66 | Dim ret = New Currency
|
---|
| 67 | VarCyAdd(This.cy, y.cy, ret.cy)
|
---|
| 68 | Return ret
|
---|
| 69 | End Function
|
---|
| 70 |
|
---|
| 71 | Const Function Operator -(y As Currency) As Currency
|
---|
| 72 | Dim ret = New Currency
|
---|
| 73 | VarCySub(This.cy, y.cy, ret.cy)
|
---|
| 74 | Return ret
|
---|
| 75 | End Function
|
---|
| 76 |
|
---|
[208] | 77 | Static Function Compare(x As Currency, y As Currency) As HRESULT
|
---|
| 78 | Return VarCyCmp(x, y)
|
---|
| 79 | End Function
|
---|
| 80 |
|
---|
| 81 | Static Function Compare(x As Currency, y As Double) As HRESULT
|
---|
| 82 | Return VarCyCmpR8(x, y)
|
---|
| 83 | End Function
|
---|
| 84 |
|
---|
| 85 | Static Function Compare(x As Double, y As Currency) As HRESULT
|
---|
| 86 | Dim ret = VarCyCmpR8(y, x)
|
---|
| 87 | Select Case ret
|
---|
| 88 | Case VARCMP_LT
|
---|
| 89 | Return VARCMP_GT
|
---|
| 90 | Case VARCMP_GT
|
---|
| 91 | Return VARCMP_LT
|
---|
| 92 | Case Else
|
---|
| 93 | Return ret
|
---|
| 94 | End Select
|
---|
| 95 | End Function
|
---|
| 96 |
|
---|
| 97 | Const Function Operator ==(y As Currency) As Boolean
|
---|
| 98 | Dim c = Compare(This, y)
|
---|
| 99 | Return c = VARCMP_EQ
|
---|
| 100 | End Function
|
---|
| 101 |
|
---|
| 102 | Const Function Operator ==(y As Double) As Boolean
|
---|
| 103 | Dim c = Compare(This, y)
|
---|
| 104 | Return c = VARCMP_EQ
|
---|
| 105 | End Function
|
---|
| 106 |
|
---|
| 107 | Const Function Operator <>(y As Currency) As Boolean
|
---|
| 108 | Dim c = Compare(This, y)
|
---|
| 109 | Return c <> VARCMP_EQ
|
---|
| 110 | End Function
|
---|
| 111 |
|
---|
| 112 | Const Function Operator <>(y As Double) As Boolean
|
---|
| 113 | Dim c = Compare(This, y)
|
---|
| 114 | Return c <> VARCMP_EQ
|
---|
| 115 | End Function
|
---|
| 116 |
|
---|
| 117 | Const Function Operator <(y As Currency) As Boolean
|
---|
| 118 | Dim c = Compare(This, y)
|
---|
| 119 | Return c = VARCMP_LT
|
---|
| 120 | End Function
|
---|
| 121 |
|
---|
| 122 | Const Function Operator <(y As Double) As Boolean
|
---|
| 123 | Dim c = Compare(This, y)
|
---|
| 124 | Return c = VARCMP_LT
|
---|
| 125 | End Function
|
---|
| 126 | /*
|
---|
| 127 | Const Function Operator >(y As Currency) As Boolean
|
---|
| 128 | Dim c = Compare(This, y)
|
---|
| 129 | Return c = VARCMP_GT
|
---|
| 130 | End Function
|
---|
| 131 |
|
---|
| 132 | Const Function Operator >(y As Double) As Boolean
|
---|
| 133 | Dim c = Compare(This, y)
|
---|
| 134 | Return c = VARCMP_GT
|
---|
| 135 | End Function
|
---|
| 136 | */
|
---|
| 137 | Const Function Operator <=(y As Currency) As Boolean
|
---|
| 138 | Dim c = Compare(This, y)
|
---|
| 139 | Return result = VARCMP_LT Or result = VARCMP_EQ
|
---|
| 140 | End Function
|
---|
| 141 |
|
---|
| 142 | Const Function Operator <=(y As Double) As Boolean
|
---|
| 143 | Dim c = Compare(This, y)
|
---|
| 144 | Return result = VARCMP_LT Or result = VARCMP_EQ
|
---|
| 145 | End Function
|
---|
| 146 |
|
---|
| 147 | Const Function Operator >=(y As Currency) As Boolean
|
---|
| 148 | Dim c = Compare(This, y)
|
---|
| 149 | Return result = VARCMP_GT Or result = VARCMP_EQ
|
---|
| 150 | End Function
|
---|
| 151 |
|
---|
| 152 | Const Function Operator >=(y As Double) As Boolean
|
---|
| 153 | Dim c = Compare(This, y)
|
---|
| 154 | Return result = VARCMP_GT Or result = VARCMP_EQ
|
---|
| 155 | End Function
|
---|
| 156 |
|
---|
[192] | 157 | Const Function Abs() As Currency
|
---|
[208] | 158 | Abs = New Currency
|
---|
[192] | 159 | VarCyAbs(This.cy, Abs.cy)
|
---|
| 160 | End Function
|
---|
| 161 |
|
---|
| 162 | Const Function Fix() As Currency
|
---|
[208] | 163 | Fix = New Currency
|
---|
[192] | 164 | VarCyFix(This.cy, Fix.cy)
|
---|
| 165 | End Function
|
---|
| 166 |
|
---|
| 167 | Const Function Int() As Currency
|
---|
[208] | 168 | Int = New Currency
|
---|
[192] | 169 | VarCyInt(This.cy, Int.cy)
|
---|
| 170 | End Function
|
---|
| 171 |
|
---|
| 172 | Const Function Round(c = 0 As Long) As Currency
|
---|
[208] | 173 | Round = New Currency
|
---|
[192] | 174 | VarCyRound(This.cy, c, Round.cy)
|
---|
| 175 | End Function
|
---|
[200] | 176 |
|
---|
| 177 | Const Function Cy() As CY
|
---|
| 178 | Return cy
|
---|
| 179 | End Function
|
---|
| 180 |
|
---|
| 181 | Sub Cy(c As CY)
|
---|
| 182 | cy = c
|
---|
| 183 | End Sub
|
---|
| 184 |
|
---|
| 185 | Const Function ToDouble() As Double
|
---|
| 186 | VarR8FromCy(cy, ToDouble)
|
---|
| 187 | End Function
|
---|
| 188 |
|
---|
| 189 | Const Function ToInt64() As Int64
|
---|
| 190 | VarI8FromCy(cy, ToInt64)
|
---|
| 191 | End Function
|
---|
| 192 |
|
---|
| 193 | Const Function ToVariant() As Variant
|
---|
| 194 | Return New Variant(This)
|
---|
| 195 | End Function
|
---|
| 196 |
|
---|
| 197 | Override Function ToString() As String
|
---|
| 198 | Dim bs As BSTR
|
---|
| 199 | VarBstrFromCy(cy, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
|
---|
| 200 | ToString = New String(bs As PCWSTR, SysStringLen(bs) As Long)
|
---|
| 201 | SysFreeString(bs)
|
---|
| 202 | End Function
|
---|
| 203 |
|
---|
| 204 | Override Function GetHashCode() As Long
|
---|
| 205 | Return HIDWORD(cy) Xor LODWORD(cy)
|
---|
| 206 | End Function
|
---|
[211] | 207 |
|
---|
| 208 | Function Equals(y As Currency) As Boolean
|
---|
| 209 | Dim c = Compare(This, y)
|
---|
| 210 | Return c = VARCMP_EQ
|
---|
| 211 | End Function
|
---|
[192] | 212 | Private
|
---|
| 213 | cy As CY
|
---|
| 214 | End Class
|
---|
[200] | 215 |
|
---|
| 216 | #endif '_COM_CURRENCY_AB
|
---|