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