xref: /aoo42x/main/basic/source/sbx/sbxdate.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 <vcl/svapp.hxx>
31*cdf0e10cSrcweir #include <svl/zforlist.hxx>
32*cdf0e10cSrcweir #include <tools/errcode.hxx>
33*cdf0e10cSrcweir #include <tools/color.hxx>
34*cdf0e10cSrcweir #include <i18npool/lang.h>
35*cdf0e10cSrcweir #include <basic/sbx.hxx>
36*cdf0e10cSrcweir #include "sbxconv.hxx"
37*cdf0e10cSrcweir #include "math.h"
38*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir double ImpGetDate( const SbxValues* p )
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir 	double nRes;
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 			nRes = p->nUShort; break;
60*cdf0e10cSrcweir 		case SbxLONG:
61*cdf0e10cSrcweir 			nRes = (double) p->nLong; break;
62*cdf0e10cSrcweir 		case SbxULONG:
63*cdf0e10cSrcweir 			nRes = (double) p->nULong; break;
64*cdf0e10cSrcweir 		case SbxSINGLE:
65*cdf0e10cSrcweir 			nRes = p->nSingle; break;
66*cdf0e10cSrcweir 		case SbxDATE:
67*cdf0e10cSrcweir 		case SbxDOUBLE:
68*cdf0e10cSrcweir 			nRes = p->nDouble; break;
69*cdf0e10cSrcweir 		case SbxULONG64:
70*cdf0e10cSrcweir 			nRes = ImpUINT64ToDouble( p->nULong64 ); break;
71*cdf0e10cSrcweir 		case SbxLONG64:
72*cdf0e10cSrcweir 			nRes = ImpINT64ToDouble( p->nLong64 ); break;
73*cdf0e10cSrcweir 		case SbxCURRENCY:
74*cdf0e10cSrcweir 			nRes = ImpCurrencyToDouble( p->nLong64 ); break;
75*cdf0e10cSrcweir 		case SbxSALINT64:
76*cdf0e10cSrcweir             nRes = static_cast< double >(p->nInt64); break;
77*cdf0e10cSrcweir 		case SbxSALUINT64:
78*cdf0e10cSrcweir             nRes = ImpSalUInt64ToDouble( p->uInt64 ); break;
79*cdf0e10cSrcweir 		case SbxDECIMAL:
80*cdf0e10cSrcweir 		case SbxBYREF | SbxDECIMAL:
81*cdf0e10cSrcweir 			if( p->pDecimal )
82*cdf0e10cSrcweir 				p->pDecimal->getDouble( nRes );
83*cdf0e10cSrcweir 			else
84*cdf0e10cSrcweir 				nRes = 0.0;
85*cdf0e10cSrcweir 			break;
86*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
87*cdf0e10cSrcweir 		case SbxSTRING:
88*cdf0e10cSrcweir 		case SbxLPSTR:
89*cdf0e10cSrcweir 			if( !p->pOUString )
90*cdf0e10cSrcweir 				nRes = 0;
91*cdf0e10cSrcweir 			else
92*cdf0e10cSrcweir 			{
93*cdf0e10cSrcweir                 LanguageType eLangType = GetpApp()->GetSettings().GetLanguage();
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 				SvNumberFormatter* pFormatter;
96*cdf0e10cSrcweir 				com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
97*cdf0e10cSrcweir 					xFactory = comphelper::getProcessServiceFactory();
98*cdf0e10cSrcweir 				pFormatter = new SvNumberFormatter( xFactory, eLangType );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 				sal_uInt32 nIndex;
101*cdf0e10cSrcweir 				xub_StrLen nCheckPos = 0;
102*cdf0e10cSrcweir 				short nType = 127;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 				// Standard-Vorlagen des Formatters haben nur zweistellige
105*cdf0e10cSrcweir 				// Jahreszahl. Deshalb eigenes Format registrieren
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 				// HACK, da der Numberformatter in PutandConvertEntry die Platzhalter
108*cdf0e10cSrcweir 				// fuer Monat, Tag, Jahr nicht entsprechend der Systemeinstellung
109*cdf0e10cSrcweir 				// austauscht. Problem: Print Year(Date) unter engl. BS
110*cdf0e10cSrcweir 				// siehe auch basic\source\runtime\runtime.cxx
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir                 SvtSysLocale aSysLocale;
113*cdf0e10cSrcweir                 DateFormat eDate = aSysLocale.GetLocaleData().getDateFormat();
114*cdf0e10cSrcweir 				String aDateStr;
115*cdf0e10cSrcweir 				switch( eDate )
116*cdf0e10cSrcweir 				{
117*cdf0e10cSrcweir 					case MDY: aDateStr.AssignAscii( "MM.TT.JJJJ" ); break;
118*cdf0e10cSrcweir 					case DMY: aDateStr.AssignAscii( "TT.MM.JJJJ" ); break;
119*cdf0e10cSrcweir 					case YMD: aDateStr.AssignAscii( "JJJJ.MM.TT" ); break;
120*cdf0e10cSrcweir 					default:  aDateStr.AssignAscii( "MM.TT.JJJJ" );
121*cdf0e10cSrcweir 				}
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 				String aStr( aDateStr );
124*cdf0e10cSrcweir 				aStr.AppendAscii( " HH:MM:SS" );
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 				pFormatter->PutandConvertEntry( aStr, nCheckPos,	nType,
127*cdf0e10cSrcweir 					nIndex, LANGUAGE_GERMAN, eLangType );
128*cdf0e10cSrcweir 				sal_Bool bSuccess = pFormatter->IsNumberFormat( *p->pOUString, nIndex, nRes );
129*cdf0e10cSrcweir 				if ( bSuccess )
130*cdf0e10cSrcweir 				{
131*cdf0e10cSrcweir 					short nType_ = pFormatter->GetType( nIndex );
132*cdf0e10cSrcweir 					if(!(nType_ & (	NUMBERFORMAT_DATETIME | NUMBERFORMAT_DATE |
133*cdf0e10cSrcweir 									NUMBERFORMAT_TIME | NUMBERFORMAT_DEFINED )))
134*cdf0e10cSrcweir 						bSuccess = sal_False;
135*cdf0e10cSrcweir 				}
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 				if ( !bSuccess )
138*cdf0e10cSrcweir 				{
139*cdf0e10cSrcweir 					SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
140*cdf0e10cSrcweir 				}
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 				delete pFormatter;
143*cdf0e10cSrcweir 			}
144*cdf0e10cSrcweir 			break;
145*cdf0e10cSrcweir 		case SbxOBJECT:
146*cdf0e10cSrcweir 		{
147*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
148*cdf0e10cSrcweir 			if( pVal )
149*cdf0e10cSrcweir 				nRes = pVal->GetDate();
150*cdf0e10cSrcweir 			else
151*cdf0e10cSrcweir 			{
152*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
153*cdf0e10cSrcweir 			}
154*cdf0e10cSrcweir 			break;
155*cdf0e10cSrcweir 		}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
158*cdf0e10cSrcweir 			nRes = *p->pChar; break;
159*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
160*cdf0e10cSrcweir 			nRes = *p->pByte; break;
161*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
162*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
163*cdf0e10cSrcweir 			nRes = *p->pInteger; break;
164*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
165*cdf0e10cSrcweir 			nRes = *p->pLong; break;
166*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
167*cdf0e10cSrcweir 			nRes = *p->pULong; break;
168*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
169*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
170*cdf0e10cSrcweir 			nRes = *p->pUShort; break;
171*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
172*cdf0e10cSrcweir 			nRes = *p->pSingle; break;
173*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
174*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
175*cdf0e10cSrcweir 			nRes = *p->pDouble; break;
176*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG64:
177*cdf0e10cSrcweir 			nRes = ImpUINT64ToDouble( *p->pULong64 ); break;
178*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG64:
179*cdf0e10cSrcweir 			nRes = ImpINT64ToDouble( *p->pLong64 ); break;
180*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
181*cdf0e10cSrcweir 			nRes = ImpCurrencyToDouble( *p->pLong64 ); break;
182*cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
183*cdf0e10cSrcweir             nRes = static_cast< double >(*p->pnInt64); break;
184*cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
185*cdf0e10cSrcweir             nRes = ImpSalUInt64ToDouble( *p->puInt64 ); break;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 		default:
188*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir 	return nRes;
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir void ImpPutDate( SbxValues* p, double n )
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	SbxValues aTmp;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir start:
198*cdf0e10cSrcweir 	switch( +p->eType )
199*cdf0e10cSrcweir 	{
200*cdf0e10cSrcweir 		case SbxDATE:
201*cdf0e10cSrcweir 		case SbxDOUBLE:
202*cdf0e10cSrcweir 			p->nDouble = n; break;
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		// ab hier wird getestet
205*cdf0e10cSrcweir 		case SbxCHAR:
206*cdf0e10cSrcweir 			aTmp.pChar = &p->nChar; goto direct;
207*cdf0e10cSrcweir 		case SbxBYTE:
208*cdf0e10cSrcweir 			aTmp.pByte = &p->nByte; goto direct;
209*cdf0e10cSrcweir 		case SbxINTEGER:
210*cdf0e10cSrcweir 		case SbxBOOL:
211*cdf0e10cSrcweir 			aTmp.pInteger = &p->nInteger; goto direct;
212*cdf0e10cSrcweir 		case SbxLONG:
213*cdf0e10cSrcweir 			aTmp.pLong = &p->nLong; goto direct;
214*cdf0e10cSrcweir 		case SbxULONG:
215*cdf0e10cSrcweir 			aTmp.pULong = &p->nULong; goto direct;
216*cdf0e10cSrcweir 		case SbxERROR:
217*cdf0e10cSrcweir 		case SbxUSHORT:
218*cdf0e10cSrcweir 			aTmp.pUShort = &p->nUShort; goto direct;
219*cdf0e10cSrcweir 		case SbxSINGLE:
220*cdf0e10cSrcweir 			aTmp.pSingle = &p->nSingle; goto direct;
221*cdf0e10cSrcweir 		case SbxULONG64:
222*cdf0e10cSrcweir 			aTmp.pULong64 = &p->nULong64; goto direct;
223*cdf0e10cSrcweir 		case SbxLONG64:
224*cdf0e10cSrcweir 		case SbxCURRENCY:
225*cdf0e10cSrcweir 			aTmp.pLong64 = &p->nLong64; goto direct;
226*cdf0e10cSrcweir 		case SbxSALINT64:
227*cdf0e10cSrcweir 			aTmp.pnInt64 = &p->nInt64; goto direct;
228*cdf0e10cSrcweir 		case SbxSALUINT64:
229*cdf0e10cSrcweir 			aTmp.puInt64 = &p->uInt64; goto direct;
230*cdf0e10cSrcweir 		case SbxDECIMAL:
231*cdf0e10cSrcweir 		case SbxBYREF | SbxDECIMAL:
232*cdf0e10cSrcweir 			{
233*cdf0e10cSrcweir 			SbxDecimal* pDec = ImpCreateDecimal( p );
234*cdf0e10cSrcweir 			if( !pDec->setDouble( n ) )
235*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW );
236*cdf0e10cSrcweir 			break;
237*cdf0e10cSrcweir 			}
238*cdf0e10cSrcweir 		direct:
239*cdf0e10cSrcweir 			aTmp.eType = SbxDataType( p->eType | SbxBYREF );
240*cdf0e10cSrcweir 			p = &aTmp; goto start;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
243*cdf0e10cSrcweir 		case SbxSTRING:
244*cdf0e10cSrcweir 		case SbxLPSTR:
245*cdf0e10cSrcweir 		{
246*cdf0e10cSrcweir 			if( !p->pOUString )
247*cdf0e10cSrcweir 				p->pOUString = new ::rtl::OUString;
248*cdf0e10cSrcweir 			Color* pColor;
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir             LanguageType eLangType = GetpApp()->GetSettings().GetLanguage();
251*cdf0e10cSrcweir 			SvNumberFormatter* pFormatter;
252*cdf0e10cSrcweir 			com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
253*cdf0e10cSrcweir 				xFactory = comphelper::getProcessServiceFactory();
254*cdf0e10cSrcweir 			pFormatter = new SvNumberFormatter( xFactory, eLangType );
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 			sal_uInt32 nIndex;
257*cdf0e10cSrcweir 			xub_StrLen nCheckPos = 0;
258*cdf0e10cSrcweir 			short nType;
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir             SvtSysLocale aSysLocale;
261*cdf0e10cSrcweir             DateFormat eDate = aSysLocale.GetLocaleData().getDateFormat();
262*cdf0e10cSrcweir 			String aStr;
263*cdf0e10cSrcweir 			// ist der ganzzahlige Teil 0, wollen wir kein Jahr!
264*cdf0e10cSrcweir 			if( n <= -1.0 || n >= 1.0 )
265*cdf0e10cSrcweir 			{
266*cdf0e10cSrcweir 				// Time only if != 00:00:00
267*cdf0e10cSrcweir 				if( floor( n ) == n )
268*cdf0e10cSrcweir                 {
269*cdf0e10cSrcweir 				    switch( eDate )
270*cdf0e10cSrcweir 				    {
271*cdf0e10cSrcweir 					    case MDY: aStr.AssignAscii( "MM.TT.JJJJ" ); break;
272*cdf0e10cSrcweir 					    case DMY: aStr.AssignAscii( "TT.MM.JJJJ" ); break;
273*cdf0e10cSrcweir 					    case YMD: aStr.AssignAscii( "JJJJ.MM.TT" ); break;
274*cdf0e10cSrcweir 					    default:  aStr.AssignAscii( "MM.TT.JJJJ" );
275*cdf0e10cSrcweir 				    }
276*cdf0e10cSrcweir                 }
277*cdf0e10cSrcweir 				else
278*cdf0e10cSrcweir                 {
279*cdf0e10cSrcweir 				    switch( eDate )
280*cdf0e10cSrcweir 				    {
281*cdf0e10cSrcweir 					    case MDY: aStr.AssignAscii( "MM.TT.JJJJ HH:MM:SS" ); break;
282*cdf0e10cSrcweir 					    case DMY: aStr.AssignAscii( "TT.MM.JJJJ HH:MM:SS" ); break;
283*cdf0e10cSrcweir 					    case YMD: aStr.AssignAscii( "JJJJ.MM.TT HH:MM:SS" ); break;
284*cdf0e10cSrcweir 					    default:  aStr.AssignAscii( "MM.TT.JJJJ HH:MM:SS" );
285*cdf0e10cSrcweir 				    }
286*cdf0e10cSrcweir                 }
287*cdf0e10cSrcweir 			}
288*cdf0e10cSrcweir 			else
289*cdf0e10cSrcweir 				aStr.AppendAscii( "HH:MM:SS" );
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 			pFormatter->PutandConvertEntry( aStr,
292*cdf0e10cSrcweir 				nCheckPos,
293*cdf0e10cSrcweir 				nType,
294*cdf0e10cSrcweir 				nIndex,
295*cdf0e10cSrcweir 				LANGUAGE_GERMAN,
296*cdf0e10cSrcweir 				eLangType );
297*cdf0e10cSrcweir             String aTmpString;
298*cdf0e10cSrcweir 			pFormatter->GetOutputString( n, nIndex, aTmpString, &pColor );
299*cdf0e10cSrcweir             *p->pOUString = aTmpString;
300*cdf0e10cSrcweir 			delete pFormatter;
301*cdf0e10cSrcweir 			break;
302*cdf0e10cSrcweir 		}
303*cdf0e10cSrcweir 		case SbxOBJECT:
304*cdf0e10cSrcweir 		{
305*cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
306*cdf0e10cSrcweir 			if( pVal )
307*cdf0e10cSrcweir 				pVal->PutDate( n );
308*cdf0e10cSrcweir 			else
309*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT );
310*cdf0e10cSrcweir 			break;
311*cdf0e10cSrcweir 		}
312*cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
313*cdf0e10cSrcweir 			if( n > SbxMAXCHAR )
314*cdf0e10cSrcweir 			{
315*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
316*cdf0e10cSrcweir 			}
317*cdf0e10cSrcweir 			else if( n < SbxMINCHAR )
318*cdf0e10cSrcweir 			{
319*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
320*cdf0e10cSrcweir 			}
321*cdf0e10cSrcweir 			*p->pChar = (xub_Unicode) n; break;
322*cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
323*cdf0e10cSrcweir 			if( n > SbxMAXBYTE )
324*cdf0e10cSrcweir 			{
325*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
326*cdf0e10cSrcweir 			}
327*cdf0e10cSrcweir 			else if( n < 0 )
328*cdf0e10cSrcweir 			{
329*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
330*cdf0e10cSrcweir 			}
331*cdf0e10cSrcweir 			*p->pByte = (sal_uInt8) n; break;
332*cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
333*cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
334*cdf0e10cSrcweir 			if( n > SbxMAXINT )
335*cdf0e10cSrcweir 			{
336*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
337*cdf0e10cSrcweir 			}
338*cdf0e10cSrcweir 			else if( n < SbxMININT )
339*cdf0e10cSrcweir 			{
340*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
341*cdf0e10cSrcweir 			}
342*cdf0e10cSrcweir 			*p->pInteger = (sal_Int16) n; break;
343*cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
344*cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
345*cdf0e10cSrcweir 			if( n > SbxMAXUINT )
346*cdf0e10cSrcweir 			{
347*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
348*cdf0e10cSrcweir 			}
349*cdf0e10cSrcweir 			else if( n < 0 )
350*cdf0e10cSrcweir 			{
351*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
352*cdf0e10cSrcweir 			}
353*cdf0e10cSrcweir 			*p->pUShort = (sal_uInt16) n; break;
354*cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
355*cdf0e10cSrcweir 			if( n > SbxMAXLNG )
356*cdf0e10cSrcweir 			{
357*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
358*cdf0e10cSrcweir 			}
359*cdf0e10cSrcweir 			else if( n < SbxMINLNG )
360*cdf0e10cSrcweir 			{
361*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINLNG;
362*cdf0e10cSrcweir 			}
363*cdf0e10cSrcweir 			*p->pLong = (sal_Int32) n; break;
364*cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
365*cdf0e10cSrcweir 			if( n > SbxMAXULNG )
366*cdf0e10cSrcweir 			{
367*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
368*cdf0e10cSrcweir 			}
369*cdf0e10cSrcweir 			else if( n < 0 )
370*cdf0e10cSrcweir 			{
371*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
372*cdf0e10cSrcweir 			}
373*cdf0e10cSrcweir 			*p->pULong = (sal_uInt32) n; break;
374*cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
375*cdf0e10cSrcweir 			if( n > SbxMAXSNG )
376*cdf0e10cSrcweir 			{
377*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXSNG;
378*cdf0e10cSrcweir 			}
379*cdf0e10cSrcweir 			else if( n < SbxMINSNG )
380*cdf0e10cSrcweir 			{
381*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINSNG;
382*cdf0e10cSrcweir 			}
383*cdf0e10cSrcweir 			*p->pSingle = (float) n; break;
384*cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
385*cdf0e10cSrcweir             *p->pnInt64 = ImpDoubleToSalInt64( n ); break;
386*cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
387*cdf0e10cSrcweir 			*p->puInt64 = ImpDoubleToSalUInt64( n ); break;
388*cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
389*cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
390*cdf0e10cSrcweir 			*p->pDouble = (double) n; break;
391*cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
392*cdf0e10cSrcweir 			if( n > SbxMAXCURR )
393*cdf0e10cSrcweir 			{
394*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCURR;
395*cdf0e10cSrcweir 			}
396*cdf0e10cSrcweir 			else if( n < SbxMINCURR )
397*cdf0e10cSrcweir 			{
398*cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR;
399*cdf0e10cSrcweir 			}
400*cdf0e10cSrcweir 			*p->pLong64 = ImpDoubleToCurrency( n ); break;
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 		default:
403*cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
404*cdf0e10cSrcweir 	}
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407