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