xref: /aoo42x/main/basic/source/sbx/sbxint.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_basic.hxx"
30*cdf0e10cSrcweir #include <tools/errcode.hxx>
31*cdf0e10cSrcweir #include <basic/sbx.hxx>
32*cdf0e10cSrcweir #include "sbxconv.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir double ImpRound( double d )
35*cdf0e10cSrcweir {
36*cdf0e10cSrcweir 	return d + ( d < 0 ? -0.5 : 0.5 );
37*cdf0e10cSrcweir }
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir sal_Int16 ImpGetInteger( const SbxValues* p )
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir 	SbxValues aTmp;
42*cdf0e10cSrcweir 	sal_Int16 nRes;
43*cdf0e10cSrcweir start:
44*cdf0e10cSrcweir 	switch( +p->eType )
45*cdf0e10cSrcweir 	{
46*cdf0e10cSrcweir 		case SbxNULL:
47*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
48*cdf0e10cSrcweir 		case SbxEMPTY:
49*cdf0e10cSrcweir 			nRes = 0; break;
50*cdf0e10cSrcweir 		case SbxCHAR:
51*cdf0e10cSrcweir 			nRes = p->nChar; break;
52*cdf0e10cSrcweir 		case SbxBYTE:
53*cdf0e10cSrcweir 			nRes = p->nByte; break;
54*cdf0e10cSrcweir 		case SbxINTEGER:
55*cdf0e10cSrcweir 		case SbxBOOL:
56*cdf0e10cSrcweir 			nRes = p->nInteger; break;
57*cdf0e10cSrcweir 		case SbxERROR:
58*cdf0e10cSrcweir 		case SbxUSHORT:
59*cdf0e10cSrcweir 			if( p->nUShort > (sal_uInt16) SbxMAXINT )
60*cdf0e10cSrcweir 			{
61*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
62*cdf0e10cSrcweir 			}
63*cdf0e10cSrcweir 			else
64*cdf0e10cSrcweir 				nRes = (sal_Int16) p->nUShort;
65*cdf0e10cSrcweir 			break;
66*cdf0e10cSrcweir 		case SbxLONG:
67*cdf0e10cSrcweir 			if( p->nLong > SbxMAXINT )
68*cdf0e10cSrcweir 			{
69*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
70*cdf0e10cSrcweir 			}
71*cdf0e10cSrcweir 			else if( p->nLong < SbxMININT )
72*cdf0e10cSrcweir 			{
73*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
74*cdf0e10cSrcweir 			}
75*cdf0e10cSrcweir 			else
76*cdf0e10cSrcweir 				nRes = (sal_Int16) p->nLong;
77*cdf0e10cSrcweir 			break;
78*cdf0e10cSrcweir 		case SbxULONG:
79*cdf0e10cSrcweir 			if( p->nULong > SbxMAXINT )
80*cdf0e10cSrcweir 			{
81*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
82*cdf0e10cSrcweir 			}
83*cdf0e10cSrcweir 			else
84*cdf0e10cSrcweir 				nRes = (sal_Int16) p->nULong;
85*cdf0e10cSrcweir 			break;
86*cdf0e10cSrcweir 		case SbxSINGLE:
87*cdf0e10cSrcweir 			if( p->nSingle > SbxMAXINT )
88*cdf0e10cSrcweir 			{
89*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
90*cdf0e10cSrcweir 			}
91*cdf0e10cSrcweir 			else if( p->nSingle < SbxMININT )
92*cdf0e10cSrcweir 			{
93*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
94*cdf0e10cSrcweir 			}
95*cdf0e10cSrcweir 			else
96*cdf0e10cSrcweir 				nRes = (sal_Int16) ImpRound( p->nSingle );
97*cdf0e10cSrcweir 			break;
98*cdf0e10cSrcweir 		case SbxSALINT64:
99*cdf0e10cSrcweir 			if( p->nInt64 > SbxMAXINT )
100*cdf0e10cSrcweir 			{
101*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
102*cdf0e10cSrcweir 			}
103*cdf0e10cSrcweir 			else if( p->nInt64 < SbxMININT )
104*cdf0e10cSrcweir 			{
105*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
106*cdf0e10cSrcweir 			}
107*cdf0e10cSrcweir 			else
108*cdf0e10cSrcweir 				nRes = (sal_Int16) p->nInt64;
109*cdf0e10cSrcweir 			break;
110*cdf0e10cSrcweir 		case SbxSALUINT64:
111*cdf0e10cSrcweir 			if( p->uInt64 > SbxMAXINT )
112*cdf0e10cSrcweir 			{
113*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
114*cdf0e10cSrcweir 			}
115*cdf0e10cSrcweir 			else
116*cdf0e10cSrcweir 				nRes = (sal_Int16) p->uInt64;
117*cdf0e10cSrcweir 			break;
118*cdf0e10cSrcweir 		case SbxDATE:
119*cdf0e10cSrcweir 		case SbxDOUBLE:
120*cdf0e10cSrcweir 		case SbxLONG64:
121*cdf0e10cSrcweir 		case SbxULONG64:
122*cdf0e10cSrcweir 		case SbxCURRENCY:
123*cdf0e10cSrcweir 		case SbxDECIMAL:
124*cdf0e10cSrcweir 		case SbxBYREF | SbxDECIMAL:
125*cdf0e10cSrcweir 			{
126*cdf0e10cSrcweir 			double dVal;
127*cdf0e10cSrcweir 			if( p->eType ==	SbxCURRENCY )
128*cdf0e10cSrcweir 				dVal = ImpCurrencyToDouble( p->nLong64 );
129*cdf0e10cSrcweir 			else if( p->eType == SbxLONG64 )
130*cdf0e10cSrcweir 				dVal = ImpINT64ToDouble( p->nLong64 );
131*cdf0e10cSrcweir 			else if( p->eType == SbxULONG64 )
132*cdf0e10cSrcweir 				dVal = ImpUINT64ToDouble( p->nULong64 );
133*cdf0e10cSrcweir 			else if( p->eType == SbxDECIMAL )
134*cdf0e10cSrcweir 			{
135*cdf0e10cSrcweir 				dVal = 0.0;
136*cdf0e10cSrcweir 				if( p->pDecimal )
137*cdf0e10cSrcweir 					p->pDecimal->getDouble( dVal );
138*cdf0e10cSrcweir 			}
139*cdf0e10cSrcweir 			else
140*cdf0e10cSrcweir 				dVal = p->nDouble;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 			if( dVal > SbxMAXINT )
143*cdf0e10cSrcweir 			{
144*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
145*cdf0e10cSrcweir 			}
146*cdf0e10cSrcweir 			else if( dVal < SbxMININT )
147*cdf0e10cSrcweir 			{
148*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
149*cdf0e10cSrcweir 			}
150*cdf0e10cSrcweir 			else
151*cdf0e10cSrcweir 				nRes = (sal_Int16) ImpRound( dVal );
152*cdf0e10cSrcweir 			break;
153*cdf0e10cSrcweir 			}
154*cdf0e10cSrcweir 		case SbxLPSTR:
155*cdf0e10cSrcweir 		case SbxSTRING:
156*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
157*cdf0e10cSrcweir 			if( !p->pOUString )
158*cdf0e10cSrcweir 				nRes = 0;
159*cdf0e10cSrcweir 			else
160*cdf0e10cSrcweir 			{
161*cdf0e10cSrcweir 				double d;
162*cdf0e10cSrcweir 				SbxDataType t;
163*cdf0e10cSrcweir 				if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
164*cdf0e10cSrcweir 					nRes = 0;
165*cdf0e10cSrcweir 				else if( d > SbxMAXINT )
166*cdf0e10cSrcweir 				{
167*cdf0e10cSrcweir 					SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
168*cdf0e10cSrcweir 				}
169*cdf0e10cSrcweir 				else if( d < SbxMININT )
170*cdf0e10cSrcweir 				{
171*cdf0e10cSrcweir 					SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
172*cdf0e10cSrcweir 				}
173*cdf0e10cSrcweir 				else
174*cdf0e10cSrcweir 					nRes = (sal_Int16) ImpRound( d );
175*cdf0e10cSrcweir 			}
176*cdf0e10cSrcweir 			break;
177*cdf0e10cSrcweir 		case SbxOBJECT:
178*cdf0e10cSrcweir 		{
179*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
180*cdf0e10cSrcweir 			if( pVal )
181*cdf0e10cSrcweir 				nRes = pVal->GetInteger();
182*cdf0e10cSrcweir 			else
183*cdf0e10cSrcweir 			{
184*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
185*cdf0e10cSrcweir 			}
186*cdf0e10cSrcweir 			break;
187*cdf0e10cSrcweir 		}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
190*cdf0e10cSrcweir 			nRes = *p->pChar; break;
191*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
192*cdf0e10cSrcweir 			nRes = *p->pByte; break;
193*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
194*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
195*cdf0e10cSrcweir 			nRes = *p->pInteger; break;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 		// ab hier muss getestet werden
198*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
199*cdf0e10cSrcweir 			aTmp.nLong = *p->pLong; goto ref;
200*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
201*cdf0e10cSrcweir 			aTmp.nULong = *p->pULong; goto ref;
202*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
203*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
204*cdf0e10cSrcweir 			aTmp.nUShort = *p->pUShort; goto ref;
205*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
206*cdf0e10cSrcweir 			aTmp.nSingle = *p->pSingle; goto ref;
207*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
208*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
209*cdf0e10cSrcweir 			aTmp.nDouble = *p->pDouble; goto ref;
210*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG64:
211*cdf0e10cSrcweir 			aTmp.nULong64 = *p->pULong64; goto ref;
212*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG64:
213*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
214*cdf0e10cSrcweir 			aTmp.nLong64 = *p->pLong64; goto ref;
215*cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
216*cdf0e10cSrcweir 			aTmp.nInt64 = *p->pnInt64; goto ref;
217*cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
218*cdf0e10cSrcweir 			aTmp.uInt64 = *p->puInt64; goto ref;
219*cdf0e10cSrcweir 		ref:
220*cdf0e10cSrcweir 			aTmp.eType = SbxDataType( p->eType & 0x0FFF );
221*cdf0e10cSrcweir 			p = &aTmp; goto start;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		default:
224*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
225*cdf0e10cSrcweir 	}
226*cdf0e10cSrcweir 	return nRes;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir void ImpPutInteger( SbxValues* p, sal_Int16 n )
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir 	SbxValues aTmp;
232*cdf0e10cSrcweir start:
233*cdf0e10cSrcweir 	switch( +p->eType )
234*cdf0e10cSrcweir 	{
235*cdf0e10cSrcweir 		// hier muss getestet werden
236*cdf0e10cSrcweir 		case SbxCHAR:
237*cdf0e10cSrcweir 			aTmp.pChar = &p->nChar; goto direct;
238*cdf0e10cSrcweir 		case SbxBYTE:
239*cdf0e10cSrcweir 			aTmp.pByte = &p->nByte; goto direct;
240*cdf0e10cSrcweir 		case SbxULONG:
241*cdf0e10cSrcweir 			aTmp.pULong = &p->nULong; goto direct;
242*cdf0e10cSrcweir 		case SbxERROR:
243*cdf0e10cSrcweir 		case SbxUSHORT:
244*cdf0e10cSrcweir 			aTmp.pUShort = &p->nUShort; goto direct;
245*cdf0e10cSrcweir 		case SbxSALUINT64:
246*cdf0e10cSrcweir 			aTmp.puInt64 = &p->uInt64; goto direct;
247*cdf0e10cSrcweir 		direct:
248*cdf0e10cSrcweir 			aTmp.eType = SbxDataType( p->eType | SbxBYREF );
249*cdf0e10cSrcweir 			p = &aTmp; goto start;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 		// ab hier nicht mehr
252*cdf0e10cSrcweir 		case SbxINTEGER:
253*cdf0e10cSrcweir 		case SbxBOOL:
254*cdf0e10cSrcweir 			p->nInteger = n; break;
255*cdf0e10cSrcweir 		case SbxLONG:
256*cdf0e10cSrcweir 			p->nLong = n; break;
257*cdf0e10cSrcweir 		case SbxSINGLE:
258*cdf0e10cSrcweir 			p->nSingle = n; break;
259*cdf0e10cSrcweir 		case SbxDATE:
260*cdf0e10cSrcweir 		case SbxDOUBLE:
261*cdf0e10cSrcweir 			p->nDouble = n; break;
262*cdf0e10cSrcweir 		case SbxSALINT64:
263*cdf0e10cSrcweir 			p->nInt64 = n; break;
264*cdf0e10cSrcweir 		case SbxULONG64:
265*cdf0e10cSrcweir 			p->nULong64 = ImpDoubleToUINT64( (double)n ); break;
266*cdf0e10cSrcweir 		case SbxLONG64:
267*cdf0e10cSrcweir 			p->nLong64 = ImpDoubleToINT64( (double)n ); break;
268*cdf0e10cSrcweir 		case SbxCURRENCY:
269*cdf0e10cSrcweir 			p->nLong64 = ImpDoubleToCurrency( (double)n ); break;
270*cdf0e10cSrcweir 		case SbxDECIMAL:
271*cdf0e10cSrcweir 		case SbxBYREF | SbxDECIMAL:
272*cdf0e10cSrcweir 			ImpCreateDecimal( p )->setInt( n );
273*cdf0e10cSrcweir 			break;
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 		case SbxLPSTR:
276*cdf0e10cSrcweir 		case SbxSTRING:
277*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
278*cdf0e10cSrcweir 			if( !p->pOUString )
279*cdf0e10cSrcweir 				p->pOUString = new ::rtl::OUString;
280*cdf0e10cSrcweir 			ImpCvtNum( (double) n, 0, *p->pOUString );
281*cdf0e10cSrcweir 			break;
282*cdf0e10cSrcweir 		case SbxOBJECT:
283*cdf0e10cSrcweir 		{
284*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
285*cdf0e10cSrcweir 			if( pVal )
286*cdf0e10cSrcweir 				pVal->PutInteger( n );
287*cdf0e10cSrcweir 			else
288*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT );
289*cdf0e10cSrcweir 			break;
290*cdf0e10cSrcweir 		}
291*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
292*cdf0e10cSrcweir 			if( n < SbxMINCHAR )
293*cdf0e10cSrcweir 			{
294*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
295*cdf0e10cSrcweir 			}
296*cdf0e10cSrcweir 			*p->pChar = (char) n; break;
297*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
298*cdf0e10cSrcweir 			if( n > SbxMAXBYTE )
299*cdf0e10cSrcweir 			{
300*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
301*cdf0e10cSrcweir 			}
302*cdf0e10cSrcweir 			else if( n < 0 )
303*cdf0e10cSrcweir 			{
304*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
305*cdf0e10cSrcweir 			}
306*cdf0e10cSrcweir 			*p->pByte = (sal_uInt8) n; break;
307*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
308*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
309*cdf0e10cSrcweir 			*p->pInteger = n; break;
310*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
311*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
312*cdf0e10cSrcweir 			if( n < 0 )
313*cdf0e10cSrcweir 			{
314*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
315*cdf0e10cSrcweir 			}
316*cdf0e10cSrcweir 			*p->pUShort = (sal_uInt16) n; break;
317*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
318*cdf0e10cSrcweir 			*p->pLong = (sal_Int32) n; break;
319*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
320*cdf0e10cSrcweir 			if( n < 0 )
321*cdf0e10cSrcweir 			{
322*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
323*cdf0e10cSrcweir 			}
324*cdf0e10cSrcweir 			*p->pULong = (sal_uInt32) n; break;
325*cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
326*cdf0e10cSrcweir 			*p->pnInt64 = n; break;
327*cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
328*cdf0e10cSrcweir 	        if( n < 0 )
329*cdf0e10cSrcweir             {
330*cdf0e10cSrcweir 		        SbxBase::SetError( SbxERR_OVERFLOW ); *p->puInt64 = 0;
331*cdf0e10cSrcweir             }
332*cdf0e10cSrcweir             else
333*cdf0e10cSrcweir 			    *p->puInt64 = n;
334*cdf0e10cSrcweir             break;
335*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
336*cdf0e10cSrcweir 			*p->pSingle = (float) n; break;
337*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
338*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
339*cdf0e10cSrcweir 			*p->pDouble = (double) n; break;
340*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG64:
341*cdf0e10cSrcweir 			*p->pULong64 = ImpDoubleToUINT64( (double)n ); break;
342*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG64:
343*cdf0e10cSrcweir 			*p->pLong64 = ImpDoubleToINT64( (double)n ); break;
344*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
345*cdf0e10cSrcweir 			*p->pLong64 = ImpDoubleToCurrency( (double)n ); break;
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 		default:
348*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
349*cdf0e10cSrcweir 	}
350*cdf0e10cSrcweir }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir // sal_Int64 / hyper
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir sal_Int64 ImpDoubleToSalInt64( double d )
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir     sal_Int64 nRes;
358*cdf0e10cSrcweir 	if( d > SbxMAXSALINT64 )
359*cdf0e10cSrcweir 	{
360*cdf0e10cSrcweir 		SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
361*cdf0e10cSrcweir 	}
362*cdf0e10cSrcweir 	else if( d < SbxMINSALINT64 )
363*cdf0e10cSrcweir 	{
364*cdf0e10cSrcweir 		SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINSALINT64;
365*cdf0e10cSrcweir 	}
366*cdf0e10cSrcweir 	else
367*cdf0e10cSrcweir 		nRes = (sal_Int64) ImpRound( d );
368*cdf0e10cSrcweir     return nRes;
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir sal_uInt64 ImpDoubleToSalUInt64( double d )
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     sal_uInt64 nRes;
374*cdf0e10cSrcweir 	if( d > SbxMAXSALUINT64 )
375*cdf0e10cSrcweir 	{
376*cdf0e10cSrcweir 		SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
377*cdf0e10cSrcweir 	}
378*cdf0e10cSrcweir 	else if( d < 0.0 )
379*cdf0e10cSrcweir 	{
380*cdf0e10cSrcweir 		SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
381*cdf0e10cSrcweir 	}
382*cdf0e10cSrcweir 	else
383*cdf0e10cSrcweir 		nRes = (sal_uInt64) ImpRound( d );
384*cdf0e10cSrcweir     return nRes;
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir double ImpSalUInt64ToDouble( sal_uInt64 n )
388*cdf0e10cSrcweir {
389*cdf0e10cSrcweir     double d = 0.0;
390*cdf0e10cSrcweir     if( n > SbxMAXSALINT64 )
391*cdf0e10cSrcweir         SbxBase::SetError( SbxERR_CONVERSION );
392*cdf0e10cSrcweir     else
393*cdf0e10cSrcweir 	    d = (double)(sal_Int64) n;
394*cdf0e10cSrcweir     return d;
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir sal_Int64 ImpGetInt64( const SbxValues* p )
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir 	SbxValues aTmp;
401*cdf0e10cSrcweir 	sal_Int64 nRes;
402*cdf0e10cSrcweir start:
403*cdf0e10cSrcweir 	switch( +p->eType )
404*cdf0e10cSrcweir 	{
405*cdf0e10cSrcweir 		case SbxNULL:
406*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
407*cdf0e10cSrcweir 		case SbxEMPTY:
408*cdf0e10cSrcweir 			nRes = 0; break;
409*cdf0e10cSrcweir 		case SbxCHAR:
410*cdf0e10cSrcweir 			nRes = p->nChar; break;
411*cdf0e10cSrcweir 		case SbxBYTE:
412*cdf0e10cSrcweir 			nRes = p->nByte; break;
413*cdf0e10cSrcweir 		case SbxINTEGER:
414*cdf0e10cSrcweir 		case SbxBOOL:
415*cdf0e10cSrcweir 			nRes = p->nInteger; break;
416*cdf0e10cSrcweir 		case SbxERROR:
417*cdf0e10cSrcweir 		case SbxUSHORT:
418*cdf0e10cSrcweir 			nRes = p->nUShort; break;
419*cdf0e10cSrcweir 		case SbxLONG:
420*cdf0e10cSrcweir 			nRes = p->nLong; break;
421*cdf0e10cSrcweir 		case SbxULONG:
422*cdf0e10cSrcweir 			nRes = (sal_Int64) p->nULong; break;
423*cdf0e10cSrcweir 		case SbxSINGLE:
424*cdf0e10cSrcweir             nRes = ImpDoubleToSalInt64( (double)p->nSingle );
425*cdf0e10cSrcweir 			break;
426*cdf0e10cSrcweir 		case SbxDATE:
427*cdf0e10cSrcweir 		case SbxDOUBLE:
428*cdf0e10cSrcweir 		case SbxLONG64:
429*cdf0e10cSrcweir 		case SbxULONG64:
430*cdf0e10cSrcweir 		case SbxCURRENCY:
431*cdf0e10cSrcweir 			{
432*cdf0e10cSrcweir 			double dVal;
433*cdf0e10cSrcweir 			if( p->eType ==	SbxCURRENCY )
434*cdf0e10cSrcweir 				dVal = ImpCurrencyToDouble( p->nLong64 );
435*cdf0e10cSrcweir 			else if( p->eType == SbxLONG64 )
436*cdf0e10cSrcweir 				dVal = ImpINT64ToDouble( p->nLong64 );
437*cdf0e10cSrcweir 			else if( p->eType == SbxULONG64 )
438*cdf0e10cSrcweir 				dVal = ImpUINT64ToDouble( p->nULong64 );
439*cdf0e10cSrcweir 			else
440*cdf0e10cSrcweir 				dVal = p->nDouble;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir             nRes = ImpDoubleToSalInt64( dVal );
443*cdf0e10cSrcweir 			break;
444*cdf0e10cSrcweir 			}
445*cdf0e10cSrcweir         case SbxSALINT64:
446*cdf0e10cSrcweir 		    nRes = p->nInt64; break;
447*cdf0e10cSrcweir 		case SbxSALUINT64:
448*cdf0e10cSrcweir 			if( p->uInt64 > SbxMAXSALINT64 )
449*cdf0e10cSrcweir 			{
450*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
451*cdf0e10cSrcweir 			}
452*cdf0e10cSrcweir 			else
453*cdf0e10cSrcweir 				nRes = (sal_Int64) p->uInt64;
454*cdf0e10cSrcweir 			break;
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
457*cdf0e10cSrcweir 		case SbxSTRING:
458*cdf0e10cSrcweir 		case SbxLPSTR:
459*cdf0e10cSrcweir 			if( !p->pOUString )
460*cdf0e10cSrcweir 				nRes = 0;
461*cdf0e10cSrcweir 			else
462*cdf0e10cSrcweir 			{
463*cdf0e10cSrcweir                	::rtl::OString aOStr = ::rtl::OUStringToOString
464*cdf0e10cSrcweir                     ( *p->pOUString, RTL_TEXTENCODING_ASCII_US );
465*cdf0e10cSrcweir                 nRes = aOStr.toInt64();
466*cdf0e10cSrcweir                 if( nRes == 0 )
467*cdf0e10cSrcweir                 {
468*cdf0e10cSrcweir                     // Check if really 0 or invalid conversion
469*cdf0e10cSrcweir 				    double d;
470*cdf0e10cSrcweir 				    SbxDataType t;
471*cdf0e10cSrcweir 				    if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
472*cdf0e10cSrcweir 					    nRes = 0;
473*cdf0e10cSrcweir                     else
474*cdf0e10cSrcweir 					    nRes = ImpDoubleToSalInt64( d );
475*cdf0e10cSrcweir                 }
476*cdf0e10cSrcweir 			}
477*cdf0e10cSrcweir 			break;
478*cdf0e10cSrcweir 		case SbxOBJECT:
479*cdf0e10cSrcweir 		{
480*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
481*cdf0e10cSrcweir 			if( pVal )
482*cdf0e10cSrcweir 				nRes = pVal->GetInt64();
483*cdf0e10cSrcweir 			else
484*cdf0e10cSrcweir 			{
485*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
486*cdf0e10cSrcweir 			}
487*cdf0e10cSrcweir 			break;
488*cdf0e10cSrcweir 		}
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
491*cdf0e10cSrcweir 			nRes = *p->pChar; break;
492*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
493*cdf0e10cSrcweir 			nRes = *p->pByte; break;
494*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
495*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
496*cdf0e10cSrcweir 			nRes = *p->pInteger; break;
497*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
498*cdf0e10cSrcweir 			nRes = *p->pLong; break;
499*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
500*cdf0e10cSrcweir 			nRes = *p->pULong; break;
501*cdf0e10cSrcweir         case SbxBYREF | SbxSALINT64:
502*cdf0e10cSrcweir 		    nRes = *p->pnInt64; break;
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 		// from here the values has to be checked
505*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
506*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
507*cdf0e10cSrcweir 			aTmp.nUShort = *p->pUShort; goto ref;
508*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
509*cdf0e10cSrcweir 			aTmp.nSingle = *p->pSingle; goto ref;
510*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
511*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
512*cdf0e10cSrcweir 			aTmp.nDouble = *p->pDouble; goto ref;
513*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG64:
514*cdf0e10cSrcweir 			aTmp.nULong64 = *p->pULong64; goto ref;
515*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG64:
516*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
517*cdf0e10cSrcweir 			aTmp.nLong64 = *p->pLong64; goto ref;
518*cdf0e10cSrcweir         case SbxBYREF | SbxSALUINT64:
519*cdf0e10cSrcweir 			aTmp.uInt64 = *p->puInt64; goto ref;
520*cdf0e10cSrcweir 		ref:
521*cdf0e10cSrcweir 			aTmp.eType = SbxDataType( p->eType & 0x0FFF );
522*cdf0e10cSrcweir 			p = &aTmp; goto start;
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 		default:
525*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
526*cdf0e10cSrcweir 	}
527*cdf0e10cSrcweir 	return nRes;
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir void ImpPutInt64( SbxValues* p, sal_Int64 n )
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir 	SbxValues aTmp;
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir start:
535*cdf0e10cSrcweir 	switch( +p->eType )
536*cdf0e10cSrcweir 	{
537*cdf0e10cSrcweir 		// Check neccessary
538*cdf0e10cSrcweir 		case SbxCHAR:
539*cdf0e10cSrcweir 			aTmp.pChar = &p->nChar; goto direct;
540*cdf0e10cSrcweir 		case SbxBYTE:
541*cdf0e10cSrcweir 			aTmp.pByte = &p->nByte; goto direct;
542*cdf0e10cSrcweir 		case SbxINTEGER:
543*cdf0e10cSrcweir 		case SbxBOOL:
544*cdf0e10cSrcweir 			aTmp.pInteger = &p->nInteger; goto direct;
545*cdf0e10cSrcweir 		case SbxULONG64:
546*cdf0e10cSrcweir 			aTmp.pULong64 = &p->nULong64; goto direct;
547*cdf0e10cSrcweir 		case SbxLONG64:
548*cdf0e10cSrcweir 		case SbxCURRENCY:
549*cdf0e10cSrcweir 			aTmp.pLong64 = &p->nLong64; goto direct;
550*cdf0e10cSrcweir 		case SbxULONG:
551*cdf0e10cSrcweir 			aTmp.pULong = &p->nULong; goto direct;
552*cdf0e10cSrcweir 		case SbxERROR:
553*cdf0e10cSrcweir 		case SbxUSHORT:
554*cdf0e10cSrcweir 			aTmp.pUShort = &p->nUShort; goto direct;
555*cdf0e10cSrcweir 		case SbxLONG:
556*cdf0e10cSrcweir 			aTmp.pnInt64 = &p->nInt64; goto direct;
557*cdf0e10cSrcweir 		case SbxSALUINT64:
558*cdf0e10cSrcweir 			aTmp.puInt64 = &p->uInt64; goto direct;
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 		direct:
561*cdf0e10cSrcweir 			aTmp.eType = SbxDataType( p->eType | SbxBYREF );
562*cdf0e10cSrcweir 			p = &aTmp; goto start;
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 		// Check not neccessary
565*cdf0e10cSrcweir         case SbxSALINT64:
566*cdf0e10cSrcweir 		    p->nInt64 = n; break;
567*cdf0e10cSrcweir 		case SbxSINGLE:
568*cdf0e10cSrcweir 			p->nSingle = (float) n; break;
569*cdf0e10cSrcweir 		case SbxDATE:
570*cdf0e10cSrcweir 		case SbxDOUBLE:
571*cdf0e10cSrcweir 			p->nDouble = (double) n; break;
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
574*cdf0e10cSrcweir 		case SbxSTRING:
575*cdf0e10cSrcweir 		case SbxLPSTR:
576*cdf0e10cSrcweir         {
577*cdf0e10cSrcweir 			if( !p->pOUString )
578*cdf0e10cSrcweir 				p->pOUString = new ::rtl::OUString;
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir             ::rtl::OString  aOStr  = ::rtl::OString::valueOf( n );
581*cdf0e10cSrcweir            	(*p->pOUString) = ::rtl::OStringToOUString
582*cdf0e10cSrcweir                 ( aOStr, RTL_TEXTENCODING_ASCII_US );
583*cdf0e10cSrcweir 			break;
584*cdf0e10cSrcweir         }
585*cdf0e10cSrcweir 		case SbxOBJECT:
586*cdf0e10cSrcweir 		{
587*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
588*cdf0e10cSrcweir 			if( pVal )
589*cdf0e10cSrcweir 				pVal->PutInt64( n );
590*cdf0e10cSrcweir 			else
591*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT );
592*cdf0e10cSrcweir 			break;
593*cdf0e10cSrcweir 		}
594*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
595*cdf0e10cSrcweir 			if( n > SbxMAXCHAR )
596*cdf0e10cSrcweir 			{
597*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
598*cdf0e10cSrcweir 			}
599*cdf0e10cSrcweir 			else if( n < SbxMINCHAR )
600*cdf0e10cSrcweir 			{
601*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
602*cdf0e10cSrcweir 			}
603*cdf0e10cSrcweir 			*p->pChar = (xub_Unicode) n; break;
604*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
605*cdf0e10cSrcweir 			if( n > SbxMAXBYTE )
606*cdf0e10cSrcweir 			{
607*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
608*cdf0e10cSrcweir 			}
609*cdf0e10cSrcweir 			else if( n < 0 )
610*cdf0e10cSrcweir 			{
611*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
612*cdf0e10cSrcweir 			}
613*cdf0e10cSrcweir 			*p->pByte = (sal_uInt8) n; break;
614*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
615*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
616*cdf0e10cSrcweir 			if( n > SbxMAXINT )
617*cdf0e10cSrcweir 			{
618*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
619*cdf0e10cSrcweir 			}
620*cdf0e10cSrcweir 			else if( n < SbxMININT )
621*cdf0e10cSrcweir 			{
622*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
623*cdf0e10cSrcweir 			}
624*cdf0e10cSrcweir 			*p->pInteger = (sal_Int16) n; break;
625*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
626*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
627*cdf0e10cSrcweir 			if( n > SbxMAXUINT )
628*cdf0e10cSrcweir 			{
629*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
630*cdf0e10cSrcweir 			}
631*cdf0e10cSrcweir 			else if( n < 0 )
632*cdf0e10cSrcweir 			{
633*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
634*cdf0e10cSrcweir 			}
635*cdf0e10cSrcweir 			*p->pUShort = (sal_uInt16) n; break;
636*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
637*cdf0e10cSrcweir 			if( n > SbxMAXLNG )
638*cdf0e10cSrcweir 			{
639*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
640*cdf0e10cSrcweir 			}
641*cdf0e10cSrcweir 			else if( n < SbxMINLNG )
642*cdf0e10cSrcweir 			{
643*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINLNG;
644*cdf0e10cSrcweir 			}
645*cdf0e10cSrcweir 			*p->pLong = (sal_Int32) n; break;
646*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
647*cdf0e10cSrcweir 			if( n > SbxMAXULNG )
648*cdf0e10cSrcweir 			{
649*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
650*cdf0e10cSrcweir 			}
651*cdf0e10cSrcweir 			else if( n < 0 )
652*cdf0e10cSrcweir 			{
653*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
654*cdf0e10cSrcweir 			}
655*cdf0e10cSrcweir 			*p->pULong = (sal_uInt32) n; break;
656*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
657*cdf0e10cSrcweir 			*p->pSingle = (float) n; break;
658*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
659*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
660*cdf0e10cSrcweir 			*p->pDouble = (double) n; break;
661*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
662*cdf0e10cSrcweir 			if( n > SbxMAXCURR )
663*cdf0e10cSrcweir 			{
664*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR;
665*cdf0e10cSrcweir 			}
666*cdf0e10cSrcweir 			else if( n < SbxMINCURR )
667*cdf0e10cSrcweir 			{
668*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMINCURR;
669*cdf0e10cSrcweir 			}
670*cdf0e10cSrcweir 			*p->pLong64 = ImpDoubleToCurrency( (double)n ); break;
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
673*cdf0e10cSrcweir 			*p->pnInt64 = n; break;
674*cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
675*cdf0e10cSrcweir 			if( n < 0 )
676*cdf0e10cSrcweir 			{
677*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
678*cdf0e10cSrcweir 			}
679*cdf0e10cSrcweir 			*p->puInt64 = (sal_Int64) n; break;
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 		default:
682*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
683*cdf0e10cSrcweir 	}
684*cdf0e10cSrcweir }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir sal_uInt64 ImpGetUInt64( const SbxValues* p )
687*cdf0e10cSrcweir {
688*cdf0e10cSrcweir 	SbxValues aTmp;
689*cdf0e10cSrcweir 	sal_uInt64 nRes;
690*cdf0e10cSrcweir start:
691*cdf0e10cSrcweir 	switch( +p->eType )
692*cdf0e10cSrcweir 	{
693*cdf0e10cSrcweir 		case SbxNULL:
694*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
695*cdf0e10cSrcweir 		case SbxEMPTY:
696*cdf0e10cSrcweir 			nRes = 0; break;
697*cdf0e10cSrcweir 		case SbxCHAR:
698*cdf0e10cSrcweir 			nRes = p->nChar; break;
699*cdf0e10cSrcweir 		case SbxBYTE:
700*cdf0e10cSrcweir 			nRes = p->nByte; break;
701*cdf0e10cSrcweir 		case SbxINTEGER:
702*cdf0e10cSrcweir 		case SbxBOOL:
703*cdf0e10cSrcweir 			nRes = p->nInteger; break;
704*cdf0e10cSrcweir 		case SbxERROR:
705*cdf0e10cSrcweir 		case SbxUSHORT:
706*cdf0e10cSrcweir 			nRes = p->nUShort; break;
707*cdf0e10cSrcweir 		case SbxLONG:
708*cdf0e10cSrcweir 			nRes = p->nLong; break;
709*cdf0e10cSrcweir 		case SbxULONG:
710*cdf0e10cSrcweir 			nRes = (sal_uInt64) p->nULong; break;
711*cdf0e10cSrcweir 		case SbxSINGLE:
712*cdf0e10cSrcweir             nRes = ImpDoubleToSalUInt64( (double)p->nSingle );
713*cdf0e10cSrcweir 			break;
714*cdf0e10cSrcweir 		case SbxDATE:
715*cdf0e10cSrcweir 		case SbxDOUBLE:
716*cdf0e10cSrcweir 		case SbxLONG64:
717*cdf0e10cSrcweir 		case SbxULONG64:
718*cdf0e10cSrcweir 		case SbxCURRENCY:
719*cdf0e10cSrcweir 			{
720*cdf0e10cSrcweir 			double dVal;
721*cdf0e10cSrcweir 			if( p->eType ==	SbxCURRENCY )
722*cdf0e10cSrcweir 				dVal = ImpCurrencyToDouble( p->nLong64 );
723*cdf0e10cSrcweir 			else if( p->eType == SbxLONG64 )
724*cdf0e10cSrcweir 				dVal = ImpINT64ToDouble( p->nLong64 );
725*cdf0e10cSrcweir 			else if( p->eType == SbxULONG64 )
726*cdf0e10cSrcweir 				dVal = ImpUINT64ToDouble( p->nULong64 );
727*cdf0e10cSrcweir 			else
728*cdf0e10cSrcweir 				dVal = p->nDouble;
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir             nRes = ImpDoubleToSalUInt64( dVal );
731*cdf0e10cSrcweir 			break;
732*cdf0e10cSrcweir 			}
733*cdf0e10cSrcweir         case SbxSALINT64:
734*cdf0e10cSrcweir 			if( p->nInt64 < 0 )
735*cdf0e10cSrcweir 			{
736*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
737*cdf0e10cSrcweir 			}
738*cdf0e10cSrcweir 			else
739*cdf0e10cSrcweir 				nRes = (sal_uInt64) p->nInt64;
740*cdf0e10cSrcweir 		case SbxSALUINT64:
741*cdf0e10cSrcweir 		    nRes = p->uInt64; break;
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
744*cdf0e10cSrcweir 		case SbxSTRING:
745*cdf0e10cSrcweir 		case SbxLPSTR:
746*cdf0e10cSrcweir 			if( !p->pOUString )
747*cdf0e10cSrcweir 				nRes = 0;
748*cdf0e10cSrcweir 			else
749*cdf0e10cSrcweir 			{
750*cdf0e10cSrcweir                	::rtl::OString aOStr = ::rtl::OUStringToOString
751*cdf0e10cSrcweir                     ( *p->pOUString, RTL_TEXTENCODING_ASCII_US );
752*cdf0e10cSrcweir                 sal_Int64 n64 = aOStr.toInt64();
753*cdf0e10cSrcweir                 if( n64 == 0 )
754*cdf0e10cSrcweir                 {
755*cdf0e10cSrcweir                     // Check if really 0 or invalid conversion
756*cdf0e10cSrcweir 				    double d;
757*cdf0e10cSrcweir 				    SbxDataType t;
758*cdf0e10cSrcweir 				    if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
759*cdf0e10cSrcweir 					    nRes = 0;
760*cdf0e10cSrcweir 				    else if( d > SbxMAXSALUINT64 )
761*cdf0e10cSrcweir 				    {
762*cdf0e10cSrcweir 					    SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
763*cdf0e10cSrcweir 				    }
764*cdf0e10cSrcweir 				    else if( d < 0.0 )
765*cdf0e10cSrcweir 				    {
766*cdf0e10cSrcweir 					    SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
767*cdf0e10cSrcweir 				    }
768*cdf0e10cSrcweir 				    else
769*cdf0e10cSrcweir 					    nRes = (sal_uInt64) ImpRound( d );
770*cdf0e10cSrcweir                 }
771*cdf0e10cSrcweir 			    else if( n64 < 0 )
772*cdf0e10cSrcweir 			    {
773*cdf0e10cSrcweir 				    SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
774*cdf0e10cSrcweir 			    }
775*cdf0e10cSrcweir                 else
776*cdf0e10cSrcweir 			    {
777*cdf0e10cSrcweir 				    nRes = n64;
778*cdf0e10cSrcweir 			    }
779*cdf0e10cSrcweir 			}
780*cdf0e10cSrcweir 			break;
781*cdf0e10cSrcweir 		case SbxOBJECT:
782*cdf0e10cSrcweir 		{
783*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
784*cdf0e10cSrcweir 			if( pVal )
785*cdf0e10cSrcweir 				nRes = pVal->GetUInt64();
786*cdf0e10cSrcweir 			else
787*cdf0e10cSrcweir 			{
788*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
789*cdf0e10cSrcweir 			}
790*cdf0e10cSrcweir 			break;
791*cdf0e10cSrcweir 		}
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
794*cdf0e10cSrcweir 			nRes = *p->pChar; break;
795*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
796*cdf0e10cSrcweir 			nRes = *p->pByte; break;
797*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
798*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
799*cdf0e10cSrcweir 			nRes = *p->pInteger; break;
800*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
801*cdf0e10cSrcweir 			nRes = *p->pLong; break;
802*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
803*cdf0e10cSrcweir 			nRes = *p->pULong; break;
804*cdf0e10cSrcweir         case SbxBYREF | SbxSALUINT64:
805*cdf0e10cSrcweir 		    nRes = *p->puInt64; break;
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir 		// from here the values has to be checked
808*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
809*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
810*cdf0e10cSrcweir 			aTmp.nUShort = *p->pUShort; goto ref;
811*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
812*cdf0e10cSrcweir 			aTmp.nSingle = *p->pSingle; goto ref;
813*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
814*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
815*cdf0e10cSrcweir 			aTmp.nDouble = *p->pDouble; goto ref;
816*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG64:
817*cdf0e10cSrcweir 			aTmp.nULong64 = *p->pULong64; goto ref;
818*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG64:
819*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
820*cdf0e10cSrcweir 			aTmp.nLong64 = *p->pLong64; goto ref;
821*cdf0e10cSrcweir         case SbxBYREF | SbxSALINT64:
822*cdf0e10cSrcweir 			aTmp.nInt64 = *p->pnInt64; goto ref;
823*cdf0e10cSrcweir 		ref:
824*cdf0e10cSrcweir 			aTmp.eType = SbxDataType( p->eType & 0x0FFF );
825*cdf0e10cSrcweir 			p = &aTmp; goto start;
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir 		default:
828*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
829*cdf0e10cSrcweir 	}
830*cdf0e10cSrcweir 	return nRes;
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir void ImpPutUInt64( SbxValues* p, sal_uInt64 n )
834*cdf0e10cSrcweir {
835*cdf0e10cSrcweir 	SbxValues aTmp;
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir start:
838*cdf0e10cSrcweir 	switch( +p->eType )
839*cdf0e10cSrcweir 	{
840*cdf0e10cSrcweir 		// Check neccessary
841*cdf0e10cSrcweir 		case SbxCHAR:
842*cdf0e10cSrcweir 			aTmp.pChar = &p->nChar; goto direct;
843*cdf0e10cSrcweir 		case SbxBYTE:
844*cdf0e10cSrcweir 			aTmp.pByte = &p->nByte; goto direct;
845*cdf0e10cSrcweir 		case SbxINTEGER:
846*cdf0e10cSrcweir 		case SbxBOOL:
847*cdf0e10cSrcweir 			aTmp.pInteger = &p->nInteger; goto direct;
848*cdf0e10cSrcweir 		case SbxULONG64:
849*cdf0e10cSrcweir 			aTmp.pULong64 = &p->nULong64; goto direct;
850*cdf0e10cSrcweir 		case SbxLONG64:
851*cdf0e10cSrcweir 		case SbxCURRENCY:
852*cdf0e10cSrcweir 			aTmp.pLong64 = &p->nLong64; goto direct;
853*cdf0e10cSrcweir 		case SbxULONG:
854*cdf0e10cSrcweir 			aTmp.pULong = &p->nULong; goto direct;
855*cdf0e10cSrcweir 		case SbxERROR:
856*cdf0e10cSrcweir 		case SbxUSHORT:
857*cdf0e10cSrcweir 			aTmp.pUShort = &p->nUShort; goto direct;
858*cdf0e10cSrcweir 		case SbxLONG:
859*cdf0e10cSrcweir 			aTmp.pnInt64 = &p->nInt64; goto direct;
860*cdf0e10cSrcweir 		case SbxSALINT64:
861*cdf0e10cSrcweir 			aTmp.pnInt64 = &p->nInt64; goto direct;
862*cdf0e10cSrcweir 		case SbxSINGLE:
863*cdf0e10cSrcweir 			aTmp.pSingle = &p->nSingle; goto direct;
864*cdf0e10cSrcweir 		case SbxDATE:
865*cdf0e10cSrcweir 		case SbxDOUBLE:
866*cdf0e10cSrcweir 			aTmp.pDouble = &p->nDouble; goto direct;
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 		direct:
869*cdf0e10cSrcweir 			aTmp.eType = SbxDataType( p->eType | SbxBYREF );
870*cdf0e10cSrcweir 			p = &aTmp; goto start;
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir 		// Check not neccessary
873*cdf0e10cSrcweir         case SbxSALUINT64:
874*cdf0e10cSrcweir 		    p->uInt64 = n; break;
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
877*cdf0e10cSrcweir 		case SbxSTRING:
878*cdf0e10cSrcweir 		case SbxLPSTR:
879*cdf0e10cSrcweir 			if( !p->pOUString )
880*cdf0e10cSrcweir 				p->pOUString = new ::rtl::OUString;
881*cdf0e10cSrcweir             if( n > SbxMAXSALINT64 )
882*cdf0e10cSrcweir     			SbxBase::SetError( SbxERR_CONVERSION );
883*cdf0e10cSrcweir             else
884*cdf0e10cSrcweir             {
885*cdf0e10cSrcweir                 ::rtl::OString  aOStr  = ::rtl::OString::valueOf( (sal_Int64)n );
886*cdf0e10cSrcweir            	    (*p->pOUString) = ::rtl::OStringToOUString
887*cdf0e10cSrcweir                     ( aOStr, RTL_TEXTENCODING_ASCII_US );
888*cdf0e10cSrcweir             }
889*cdf0e10cSrcweir 			break;
890*cdf0e10cSrcweir 		case SbxOBJECT:
891*cdf0e10cSrcweir 		{
892*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
893*cdf0e10cSrcweir 			if( pVal )
894*cdf0e10cSrcweir 				pVal->PutUInt64( n );
895*cdf0e10cSrcweir 			else
896*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT );
897*cdf0e10cSrcweir 			break;
898*cdf0e10cSrcweir 		}
899*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
900*cdf0e10cSrcweir 			if( n > SbxMAXCHAR )
901*cdf0e10cSrcweir 			{
902*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
903*cdf0e10cSrcweir 			}
904*cdf0e10cSrcweir 			*p->pChar = (xub_Unicode) n; break;
905*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
906*cdf0e10cSrcweir 			if( n > SbxMAXBYTE )
907*cdf0e10cSrcweir 			{
908*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
909*cdf0e10cSrcweir 			}
910*cdf0e10cSrcweir 			*p->pByte = (sal_uInt8) n; break;
911*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
912*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
913*cdf0e10cSrcweir 			if( n > SbxMAXINT )
914*cdf0e10cSrcweir 			{
915*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
916*cdf0e10cSrcweir 			}
917*cdf0e10cSrcweir 			*p->pInteger = (sal_Int16) n; break;
918*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
919*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
920*cdf0e10cSrcweir 			if( n > SbxMAXUINT )
921*cdf0e10cSrcweir 			{
922*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
923*cdf0e10cSrcweir 			}
924*cdf0e10cSrcweir 			*p->pUShort = (sal_uInt16) n; break;
925*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
926*cdf0e10cSrcweir 			if( n > SbxMAXLNG )
927*cdf0e10cSrcweir 			{
928*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
929*cdf0e10cSrcweir 			}
930*cdf0e10cSrcweir 			*p->pLong = (sal_Int32) n; break;
931*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
932*cdf0e10cSrcweir 			if( n > SbxMAXULNG )
933*cdf0e10cSrcweir 			{
934*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
935*cdf0e10cSrcweir 			}
936*cdf0e10cSrcweir 			*p->pULong = (sal_uInt32) n; break;
937*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
938*cdf0e10cSrcweir             *p->pDouble = (float)ImpSalUInt64ToDouble( n ); break;
939*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
940*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
941*cdf0e10cSrcweir             *p->pDouble = ImpSalUInt64ToDouble( n ); break;
942*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
943*cdf0e10cSrcweir 			if( n > SbxMAXSALINT64 || (sal_Int64)n > SbxMAXCURR )
944*cdf0e10cSrcweir 			{
945*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR;
946*cdf0e10cSrcweir 			}
947*cdf0e10cSrcweir 			*p->pLong64 = ImpDoubleToCurrency( (double)(sal_Int64) n ); break;
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
950*cdf0e10cSrcweir 			*p->puInt64 = n; break;
951*cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
952*cdf0e10cSrcweir 			if( n > SbxMAXSALINT64 )
953*cdf0e10cSrcweir 			{
954*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
955*cdf0e10cSrcweir 			}
956*cdf0e10cSrcweir 			*p->pnInt64 = (sal_Int64) n; break;
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir 		default:
959*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
960*cdf0e10cSrcweir 	}
961*cdf0e10cSrcweir }
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir 
964