1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: methods1.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
37 #include <stdlib.h> // getenv
39 #include <vcl/svapp.hxx>
40 #include <vcl/mapmod.hxx>
41 #include <vcl/wrkwin.hxx>
42 #include <vcl/timer.hxx>
43 #include <basic/sbxvar.hxx>
45 #include <basic/sbx.hxx>
47 #include <basic/sbstar.hxx>
48 #include <svtools/zforlist.hxx>
49 #include <tools/fsys.hxx>
50 #include <tools/urlobj.hxx>
51 #include <osl/file.hxx>
55 #define INCL_DOSPROCESS
60 #include <tools/svwin.h>
64 #define CLK_TCK CLOCKS_PER_SEC
67 #include <vcl/jobset.hxx>
68 #include <basic/sbobjmod.hxx>
70 #include "sbintern.hxx"
71 #include "runtime.hxx"
73 #include "rtlproto.hxx"
76 #include "sbunoobj.hxx"
77 #include "propacc.hxx"
80 #include <comphelper/processfactory.hxx>
82 #include <com/sun/star/uno/Sequence.hxx>
83 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
84 #include <com/sun/star/i18n/XCalendar.hpp>
85 #include <com/sun/star/sheet/XFunctionAccess.hpp>
87 using namespace comphelper
;
88 using namespace com::sun::star::sheet
;
89 using namespace com::sun::star::uno
;
90 using namespace com::sun::star::i18n
;
92 void unoToSbxValue( SbxVariable
* pVar
, const Any
& aValue
);
93 Any
sbxToUnoValue( SbxVariable
* pVar
, const Type
& rType
, com::sun::star::beans::Property
* pUnoProperty
= NULL
);
95 static Reference
< XCalendar
> getLocaleCalendar( void )
97 static Reference
< XCalendar
> xCalendar
;
100 Reference
< XMultiServiceFactory
> xSMgr
= getProcessServiceFactory();
103 xCalendar
= Reference
< XCalendar
>( xSMgr
->createInstance
104 ( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.LocaleCalendar" ) ), UNO_QUERY
);
108 static com::sun::star::lang::Locale aLastLocale
;
109 static bool bNeedsInit
= true;
111 com::sun::star::lang::Locale aLocale
= Application::GetSettings().GetLocale();
112 bool bNeedsReload
= false;
118 else if( aLocale
.Language
!= aLastLocale
.Language
||
119 aLocale
.Country
!= aLastLocale
.Country
)
125 aLastLocale
= aLocale
;
126 xCalendar
->loadDefaultCalendar( aLocale
);
132 RTLFUNC(CBool
) // JSM
138 if ( rPar
.Count() == 2 )
140 SbxVariable
*pSbxVariable
= rPar
.Get(1);
141 bVal
= pSbxVariable
->GetBool();
144 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
146 rPar
.Get(0)->PutBool(bVal
);
149 RTLFUNC(CByte
) // JSM
155 if ( rPar
.Count() == 2 )
157 SbxVariable
*pSbxVariable
= rPar
.Get(1);
158 nByte
= pSbxVariable
->GetByte();
161 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
163 rPar
.Get(0)->PutByte(nByte
);
172 if ( rPar
.Count() == 2 )
174 SbxVariable
*pSbxVariable
= rPar
.Get(1);
175 nCur
= pSbxVariable
->GetCurrency();
178 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
180 rPar
.Get(0)->PutCurrency( nCur
);
189 SbxDecimal
* pDec
= NULL
;
190 if ( rPar
.Count() == 2 )
192 SbxVariable
*pSbxVariable
= rPar
.Get(1);
193 pDec
= pSbxVariable
->GetDecimal();
196 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
198 rPar
.Get(0)->PutDecimal( pDec
);
200 rPar
.Get(0)->PutEmpty();
201 StarBASIC::Error(SbERR_NOT_IMPLEMENTED
);
205 RTLFUNC(CDate
) // JSM
211 if ( rPar
.Count() == 2 )
213 SbxVariable
*pSbxVariable
= rPar
.Get(1);
214 nVal
= pSbxVariable
->GetDate();
217 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
219 rPar
.Get(0)->PutDate(nVal
);
228 if ( rPar
.Count() == 2 )
230 SbxVariable
*pSbxVariable
= rPar
.Get(1);
231 if( pSbxVariable
->GetType() == SbxSTRING
)
233 // AB #41690 , String holen
234 String aScanStr
= pSbxVariable
->GetString();
235 SbError Error
= SbxValue::ScanNumIntnl( aScanStr
, nVal
);
236 if( Error
!= SbxERR_OK
)
237 StarBASIC::Error( Error
);
241 nVal
= pSbxVariable
->GetDouble();
245 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
247 rPar
.Get(0)->PutDouble(nVal
);
256 if ( rPar
.Count() == 2 )
258 SbxVariable
*pSbxVariable
= rPar
.Get(1);
259 nVal
= pSbxVariable
->GetInteger();
262 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
264 rPar
.Get(0)->PutInteger(nVal
);
273 if ( rPar
.Count() == 2 )
275 SbxVariable
*pSbxVariable
= rPar
.Get(1);
276 nVal
= pSbxVariable
->GetLong();
279 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
281 rPar
.Get(0)->PutLong(nVal
);
289 float nVal
= (float)0.0;
290 if ( rPar
.Count() == 2 )
292 SbxVariable
*pSbxVariable
= rPar
.Get(1);
293 if( pSbxVariable
->GetType() == SbxSTRING
)
295 // AB #41690 , String holen
297 String aScanStr
= pSbxVariable
->GetString();
298 SbError Error
= SbxValue::ScanNumIntnl( aScanStr
, dVal
, /*bSingle=*/TRUE
);
299 if( SbxBase::GetError() == SbxERR_OK
&& Error
!= SbxERR_OK
)
300 StarBASIC::Error( Error
);
305 nVal
= pSbxVariable
->GetSingle();
309 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
311 rPar
.Get(0)->PutSingle(nVal
);
320 if ( rPar
.Count() == 2 )
322 SbxVariable
*pSbxVariable
= rPar
.Get(1);
323 aString
= pSbxVariable
->GetString();
326 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
328 rPar
.Get(0)->PutString(aString
);
336 SbxValues
aVals( SbxVARIANT
);
337 if ( rPar
.Count() == 2 )
339 SbxVariable
*pSbxVariable
= rPar
.Get(1);
340 pSbxVariable
->Get( aVals
);
343 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
345 rPar
.Get(0)->Put( aVals
);
354 if ( rPar
.Count() == 2 )
356 SbxVariable
*pSbxVariable
= rPar
.Get(1);
357 nErrCode
= pSbxVariable
->GetInteger();
360 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
362 rPar
.Get(0)->PutErr( nErrCode
);
370 if ( rPar
.Count() == 4 )
372 if (rPar
.Get(1)->GetBool())
373 *rPar
.Get(0) = *rPar
.Get(2);
375 *rPar
.Get(0) = *rPar
.Get(3);
378 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
381 RTLFUNC(GetSystemType
)
386 if ( rPar
.Count() != 1 )
387 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
389 // Removed for SRC595
390 rPar
.Get(0)->PutInteger( -1 );
398 if ( rPar
.Count() != 1 )
399 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
402 // 17.7.2000 Make simple solution for testtool / fat office
404 rPar
.Get(0)->PutInteger( 1 );
406 rPar
.Get(0)->PutInteger( 2 );
408 rPar
.Get(0)->PutInteger( 4 );
410 rPar
.Get(0)->PutInteger( -1 );
420 if ( rPar
.Count() != 2 )
421 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
424 ULONG nRGB
= (ULONG
)rPar
.Get(1)->GetLong();
427 rPar
.Get(0)->PutInteger( (INT16
)nRGB
);
436 if ( rPar
.Count() != 2 )
437 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
440 ULONG nRGB
= (ULONG
)rPar
.Get(1)->GetLong();
443 rPar
.Get(0)->PutInteger( (INT16
)nRGB
);
452 if ( rPar
.Count() != 2 )
453 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
456 ULONG nRGB
= (ULONG
)rPar
.Get(1)->GetLong();
458 rPar
.Get(0)->PutInteger( (INT16
)nRGB
);
468 USHORT nCount
= rPar
.Count();
469 if( !(nCount
& 0x0001 ))
470 // Anzahl der Argumente muss ungerade sein
471 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
473 while( nCurExpr
< (nCount
-1) )
475 if( rPar
.Get( nCurExpr
)->GetBool())
477 (*rPar
.Get(0)) = *(rPar
.Get(nCurExpr
+1));
482 rPar
.Get(0)->PutNull();
485 //i#64882# Common wait impl for existing Wait and new WaitUntil
487 void Wait_Impl( bool bDurationBased
, SbxArray
& rPar
)
489 if( rPar
.Count() != 2 )
491 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
495 if ( bDurationBased
)
497 double dWait
= rPar
.Get(1)->GetDouble();
498 double dNow
= Now_Impl();
499 double dSecs
= (double)( ( dWait
- dNow
) * (double)( 24.0*3600.0) );
500 nWait
= (long)( dSecs
* 1000 ); // wait in thousands of sec
503 nWait
= rPar
.Get(1)->GetLong();
506 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
511 aTimer
.SetTimeout( nWait
);
513 while ( aTimer
.IsActive() )
514 Application::Yield();
522 Wait_Impl( false, rPar
);
525 //i#64882# add new WaitUntil ( for application.wait )
526 // share wait_impl with 'normal' oobasic wait
531 Wait_Impl( true, rPar
);
534 RTLFUNC(GetGUIVersion
)
539 if ( rPar
.Count() != 1 )
540 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
543 // Removed for SRC595
544 rPar
.Get(0)->PutLong( -1 );
553 if ( rPar
.Count() < 2 )
554 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
555 INT16 nIndex
= rPar
.Get(1)->GetInteger();
556 USHORT nCount
= rPar
.Count();
558 if( nCount
== 1 || nIndex
> (nCount
-1) || nIndex
< 1 )
560 rPar
.Get(0)->PutNull();
563 (*rPar
.Get(0)) = *(rPar
.Get(nIndex
+1));
572 if ( rPar
.Count() < 2 )
573 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
576 String
aStr( rPar
.Get(1)->GetString() );
577 aStr
.EraseLeadingChars();
578 aStr
.EraseTrailingChars();
579 rPar
.Get(0)->PutString( aStr
);
583 RTLFUNC(GetSolarVersion
)
588 rPar
.Get(0)->PutLong( (INT32
)SUPD
);
591 RTLFUNC(TwipsPerPixelX
)
598 MapMode
aMap( MAP_TWIP
);
599 OutputDevice
* pDevice
= Application::GetDefaultDevice();
602 aSize
= pDevice
->PixelToLogic( aSize
, aMap
);
603 nResult
= aSize
.Width() / 100;
605 rPar
.Get(0)->PutLong( nResult
);
608 RTLFUNC(TwipsPerPixelY
)
615 MapMode
aMap( MAP_TWIP
);
616 OutputDevice
* pDevice
= Application::GetDefaultDevice();
619 aSize
= pDevice
->PixelToLogic( aSize
, aMap
);
620 nResult
= aSize
.Height() / 100;
622 rPar
.Get(0)->PutLong( nResult
);
631 if ( rPar
.Count() != 2 )
632 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
633 ByteString
aByteDLLName( rPar
.Get(1)->GetString(), gsl_getSystemTextEncoding() );
634 pINST
->GetDllMgr()->FreeDll( aByteDLLName
);
636 bool IsBaseIndexOne()
639 if ( pINST
&& pINST
->pRun
)
641 USHORT res
= pINST
->pRun
->GetBase();
653 SbxDimArray
* pArray
= new SbxDimArray( SbxVARIANT
);
654 USHORT nArraySize
= rPar
.Count() - 1;
656 // Option Base zunaechst ignorieren (kennt leider nur der Compiler)
657 bool bIncIndex
= (IsBaseIndexOne() && SbiRuntime::isVBAEnabled() );
661 pArray
->AddDim( 1, nArraySize
);
663 pArray
->AddDim( 0, nArraySize
-1 );
667 pArray
->unoAddDim( 0, -1 );
670 // Parameter ins Array uebernehmen
671 for( short i
= 0 ; i
< nArraySize
; i
++ )
673 SbxVariable
* pVar
= rPar
.Get(i
+1);
674 SbxVariable
* pNew
= new SbxVariable( *pVar
);
675 pNew
->SetFlag( SBX_WRITE
);
679 pArray
->Put( pNew
, &index
);
682 // Array zurueckliefern
683 SbxVariableRef refVar
= rPar
.Get(0);
684 USHORT nFlags
= refVar
->GetFlags();
685 refVar
->ResetFlag( SBX_FIXED
);
686 refVar
->PutObject( pArray
);
687 refVar
->SetFlags( nFlags
);
688 refVar
->SetParameters( NULL
);
692 // Featurewunsch #57868
693 // Die Funktion liefert ein Variant-Array, wenn keine Parameter angegeben
694 // werden, wird ein leeres Array erzeugt (entsprechend dim a(), entspricht
695 // einer Sequence der Laenge 0 in Uno).
696 // Wenn Parameter angegeben sind, wird fuer jeden eine Dimension erzeugt
697 // DimArray( 2, 2, 4 ) entspricht DIM a( 2, 2, 4 )
698 // Das Array ist immer vom Typ Variant
704 SbxDimArray
* pArray
= new SbxDimArray( SbxVARIANT
);
705 USHORT nArrayDims
= rPar
.Count() - 1;
708 for( USHORT i
= 0; i
< nArrayDims
; i
++ )
710 INT32 ub
= rPar
.Get(i
+1)->GetLong();
713 StarBASIC::Error( SbERR_OUT_OF_RANGE
);
716 pArray
->AddDim32( 0, ub
);
720 pArray
->unoAddDim( 0, -1 );
722 // Array zurueckliefern
723 SbxVariableRef refVar
= rPar
.Get(0);
724 USHORT nFlags
= refVar
->GetFlags();
725 refVar
->ResetFlag( SBX_FIXED
);
726 refVar
->PutObject( pArray
);
727 refVar
->SetFlags( nFlags
);
728 refVar
->SetParameters( NULL
);
732 * FindObject und FindPropertyObject ermoeglichen es,
733 * Objekte und Properties vom Typ Objekt zur Laufzeit
734 * ueber ihren Namen als String-Parameter anzusprechen.
737 * MyObj.Prop1.Bla = 5
740 * dim ObjVar as Object
741 * dim ObjProp as Object
743 * ObjVar = FindObject( ObjName$ )
744 * PropName$ = "Prop1"
745 * ObjProp = FindPropertyObject( ObjVar, PropName$ )
748 * Dabei koennen die Namen zur Laufzeit dynamisch
749 * erzeugt werden und, so dass z.B. ueber Controls
750 * "TextEdit1" bis "TextEdit5" in einem Dialog in
751 * einer Schleife iteriert werden kann.
754 // Objekt ueber den Namen ansprechen
755 // 1. Parameter = Name des Objekts als String
761 // Wir brauchen einen Parameter
762 if ( rPar
.Count() < 2 )
764 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
768 // 1. Parameter ist der Name
769 String aNameStr
= rPar
.Get(1)->GetString();
771 // Basic-Suchfunktion benutzen
772 SbxBase
* pFind
= StarBASIC::FindSBXInCurrentScope( aNameStr
);
773 SbxObject
* pFindObj
= NULL
;
775 pFindObj
= PTR_CAST(SbxObject
,pFind
);
779 StarBASIC::Error( SbERR_VAR_UNDEFINED );
784 // Objekt zurueckliefern
785 SbxVariableRef refVar
= rPar
.Get(0);
786 refVar
->PutObject( pFindObj
);
789 // Objekt-Property in einem Objekt ansprechen
790 // 1. Parameter = Objekt
791 // 2. Parameter = Name der Property als String
792 RTLFUNC(FindPropertyObject
)
797 // Wir brauchen 2 Parameter
798 if ( rPar
.Count() < 3 )
800 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
804 // 1. Parameter holen, muss Objekt sein
805 SbxBase
* pObjVar
= (SbxObject
*)rPar
.Get(1)->GetObject();
806 SbxObject
* pObj
= NULL
;
808 pObj
= PTR_CAST(SbxObject
,pObjVar
);
809 if( !pObj
&& pObjVar
&& pObjVar
->ISA(SbxVariable
) )
811 SbxBase
* pObjVarObj
= ((SbxVariable
*)pObjVar
)->GetObject();
812 pObj
= PTR_CAST(SbxObject
,pObjVarObj
);
817 StarBASIC::Error( SbERR_VAR_UNDEFINED );
822 // 2. Parameter ist der Name
823 String aNameStr
= rPar
.Get(2)->GetString();
825 // Jetzt muss ein Objekt da sein, sonst Error
826 SbxObject
* pFindObj
= NULL
;
829 // Im Objekt nach Objekt suchen
830 SbxVariable
* pFindVar
= pObj
->Find( aNameStr
, SbxCLASS_OBJECT
);
831 pFindObj
= PTR_CAST(SbxObject
,pFindVar
);
834 StarBASIC::Error( SbERR_BAD_PARAMETER
);
836 // Objekt zurueckliefern
837 SbxVariableRef refVar
= rPar
.Get(0);
838 refVar
->PutObject( pFindObj
);
843 BOOL
lcl_WriteSbxVariable( const SbxVariable
& rVar
, SvStream
* pStrm
,
844 BOOL bBinary
, short nBlockLen
, BOOL bIsArray
)
846 ULONG nFPos
= pStrm
->Tell();
848 BOOL bIsVariant
= !rVar
.IsFixed();
849 SbxDataType eType
= rVar
.GetType();
857 *pStrm
<< (USHORT
)SbxBYTE
; // VarType Id
858 *pStrm
<< rVar
.GetByte();
869 *pStrm
<< (USHORT
)SbxINTEGER
; // VarType Id
870 *pStrm
<< rVar
.GetInteger();
878 *pStrm
<< (USHORT
)SbxLONG
; // VarType Id
879 *pStrm
<< rVar
.GetLong();
884 *pStrm
<< (USHORT
)eType
; // VarType Id
885 *pStrm
<< rVar
.GetSingle();
892 *pStrm
<< (USHORT
)eType
; // VarType Id
893 *pStrm
<< rVar
.GetDouble();
899 const String
& rStr
= rVar
.GetString();
900 if( !bBinary
|| bIsArray
)
903 *pStrm
<< (USHORT
)SbxSTRING
;
904 pStrm
->WriteByteString( rStr
, gsl_getSystemTextEncoding() );
909 // ohne Laengenangabe! ohne Endekennung!
910 // What does that mean for Unicode?! Choosing conversion to ByteString...
911 ByteString
aByteStr( rStr
, gsl_getSystemTextEncoding() );
912 *pStrm
<< (const char*)aByteStr
.GetBuffer();
913 //*pStrm << (const char*)rStr.GetStr();
919 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
924 pStrm
->Seek( nFPos
+ nBlockLen
);
925 return pStrm
->GetErrorCode() ? FALSE
: TRUE
;
928 BOOL
lcl_ReadSbxVariable( SbxVariable
& rVar
, SvStream
* pStrm
,
929 BOOL bBinary
, short nBlockLen
, BOOL bIsArray
)
936 ULONG nFPos
= pStrm
->Tell();
938 BOOL bIsVariant
= !rVar
.IsFixed();
939 SbxDataType eVarType
= rVar
.GetType();
941 SbxDataType eSrcType
= eVarType
;
946 eSrcType
= (SbxDataType
)nTemp
;
957 rVar
.PutByte( aByte
);
971 rVar
.PutInteger( aInt
);
982 rVar
.PutLong( aInt
);
990 rVar
.PutSingle( nS
);
998 rVar
.PutDouble( aDouble
);
1005 rVar
.PutDate( aDouble
);
1013 pStrm
->ReadByteString( aStr
, gsl_getSystemTextEncoding() );
1014 rVar
.PutString( aStr
);
1019 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1024 pStrm
->Seek( nFPos
+ nBlockLen
);
1025 return pStrm
->GetErrorCode() ? FALSE
: TRUE
;
1030 BOOL
lcl_WriteReadSbxArray( SbxDimArray
& rArr
, SvStream
* pStrm
,
1031 BOOL bBinary
, short nCurDim
, short* pOtherDims
, BOOL bWrite
)
1033 DBG_ASSERT( nCurDim
> 0,"Bad Dim");
1034 short nLower
, nUpper
;
1035 if( !rArr
.GetDim( nCurDim
, nLower
, nUpper
) )
1037 for( short nCur
= nLower
; nCur
<= nUpper
; nCur
++ )
1039 pOtherDims
[ nCurDim
-1 ] = nCur
;
1041 lcl_WriteReadSbxArray(rArr
, pStrm
, bBinary
, nCurDim
-1, pOtherDims
, bWrite
);
1044 SbxVariable
* pVar
= rArr
.Get( (const short*)pOtherDims
);
1047 bRet
= lcl_WriteSbxVariable(*pVar
, pStrm
, bBinary
, 0, TRUE
);
1049 bRet
= lcl_ReadSbxVariable(*pVar
, pStrm
, bBinary
, 0, TRUE
);
1057 void PutGet( SbxArray
& rPar
, BOOL bPut
)
1059 // Wir brauchen 3 Parameter
1060 if ( rPar
.Count() != 4 )
1062 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1065 INT16 nFileNo
= rPar
.Get(1)->GetInteger();
1066 SbxVariable
* pVar2
= rPar
.Get(2);
1067 BOOL bHasRecordNo
= (BOOL
)(pVar2
->GetType() != SbxEMPTY
);
1068 long nRecordNo
= pVar2
->GetLong();
1069 if ( nFileNo
< 1 || ( bHasRecordNo
&& nRecordNo
< 1 ) )
1071 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1074 nRecordNo
--; // wir moegen's ab 0!
1075 SbiIoSystem
* pIO
= pINST
->GetIoSystem();
1076 SbiStream
* pSbStrm
= pIO
->GetStream( nFileNo
);
1077 // das File muss Random (feste Record-Laenge) oder Binary sein
1078 if ( !pSbStrm
|| !(pSbStrm
->GetMode() & (SBSTRM_BINARY
| SBSTRM_RANDOM
)) )
1080 StarBASIC::Error( SbERR_BAD_CHANNEL
);
1084 SvStream
* pStrm
= pSbStrm
->GetStrm();
1085 BOOL bRandom
= pSbStrm
->IsRandom();
1086 short nBlockLen
= bRandom
? pSbStrm
->GetBlockLen() : 0;
1090 // Datei aufplustern, falls jemand uebers Dateiende hinaus geseekt hat
1091 pSbStrm
->ExpandFile();
1094 // auf die Startposition seeken
1097 ULONG nFilePos
= bRandom
? (ULONG
)(nBlockLen
*nRecordNo
) : (ULONG
)nRecordNo
;
1098 pStrm
->Seek( nFilePos
);
1101 SbxDimArray
* pArr
= 0;
1102 SbxVariable
* pVar
= rPar
.Get(3);
1103 if( pVar
->GetType() & SbxARRAY
)
1105 SbxBase
* pParObj
= pVar
->GetObject();
1106 pArr
= PTR_CAST(SbxDimArray
,pParObj
);
1113 ULONG nFPos
= pStrm
->Tell();
1114 short nDims
= pArr
->GetDims();
1115 short* pDims
= new short[ nDims
];
1116 bRet
= lcl_WriteReadSbxArray(*pArr
,pStrm
,!bRandom
,nDims
,pDims
,bPut
);
1119 pStrm
->Seek( nFPos
+ nBlockLen
);
1124 bRet
= lcl_WriteSbxVariable(*pVar
, pStrm
, !bRandom
, nBlockLen
, FALSE
);
1126 bRet
= lcl_ReadSbxVariable(*pVar
, pStrm
, !bRandom
, nBlockLen
, FALSE
);
1128 if( !bRet
|| pStrm
->GetErrorCode() )
1129 StarBASIC::Error( SbERR_IO_ERROR
);
1137 PutGet( rPar
, TRUE
);
1145 PutGet( rPar
, FALSE
);
1153 if ( rPar
.Count() != 2 )
1155 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1159 // sollte ANSI sein, aber unter Win16 in DLL nicht moeglich
1161 LPSTR lpszEnv
= GetDOSEnvironment();
1162 String
aCompareStr( rPar
.Get(1)->GetString() );
1164 const char* pCompare
= aCompareStr
.GetStr();
1165 int nCompareLen
= aCompareStr
.Len();
1168 // Es werden alle EnvString in der Form ENV=VAL 0-terminiert
1169 // aneinander gehaengt.
1171 if ( strnicmp( pCompare
, lpszEnv
, nCompareLen
) == 0 )
1173 aResult
= (const char*)(lpszEnv
+nCompareLen
);
1174 rPar
.Get(0)->PutString( aResult
);
1177 lpszEnv
+= lstrlen( lpszEnv
) + 1; // Next Enviroment-String
1180 ByteString
aByteStr( rPar
.Get(1)->GetString(), gsl_getSystemTextEncoding() );
1181 const char* pEnvStr
= getenv( aByteStr
.GetBuffer() );
1183 aResult
= String::CreateFromAscii( pEnvStr
);
1185 rPar
.Get(0)->PutString( aResult
);
1188 static double GetDialogZoomFactor( BOOL bX
, long nValue
)
1190 OutputDevice
* pDevice
= Application::GetDefaultDevice();
1194 Size
aRefSize( nValue
, nValue
);
1196 Fraction
aFracX( 1, 26 );
1198 Fraction
aFracX( 1, 23 );
1200 Fraction
aFracY( 1, 24 );
1201 MapMode
aMap( MAP_APPFONT
, Point(), aFracX
, aFracY
);
1202 Size aScaledSize
= pDevice
->LogicToPixel( aRefSize
, aMap
);
1203 aRefSize
= pDevice
->LogicToPixel( aRefSize
, MapMode(MAP_TWIP
) );
1205 double nRef
, nScaled
;
1208 nRef
= aRefSize
.Width();
1209 nScaled
= aScaledSize
.Width();
1213 nRef
= aRefSize
.Height();
1214 nScaled
= aScaledSize
.Height();
1216 nResult
= nScaled
/ nRef
;
1222 RTLFUNC(GetDialogZoomFactorX
)
1227 if ( rPar
.Count() != 2 )
1229 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1232 rPar
.Get(0)->PutDouble( GetDialogZoomFactor( TRUE
, rPar
.Get(1)->GetLong() ));
1235 RTLFUNC(GetDialogZoomFactorY
)
1240 if ( rPar
.Count() != 2 )
1242 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1245 rPar
.Get(0)->PutDouble( GetDialogZoomFactor( FALSE
, rPar
.Get(1)->GetLong()));
1249 RTLFUNC(EnableReschedule
)
1254 rPar
.Get(0)->PutEmpty();
1255 if ( rPar
.Count() != 2 )
1256 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1258 pINST
->EnableReschedule( rPar
.Get(1)->GetBool() );
1261 RTLFUNC(GetSystemTicks
)
1266 if ( rPar
.Count() != 1 )
1268 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1271 rPar
.Get(0)->PutLong( Time::GetSystemTicks() );
1274 RTLFUNC(GetPathSeparator
)
1279 if ( rPar
.Count() != 1 )
1281 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1284 rPar
.Get(0)->PutString( DirEntry::GetAccessDelimiter() );
1287 RTLFUNC(ResolvePath
)
1292 if ( rPar
.Count() == 2 )
1294 String aStr
= rPar
.Get(1)->GetString();
1295 DirEntry
aEntry( aStr
);
1296 //if( aEntry.IsVirtual() )
1297 //aStr = aEntry.GetRealPathFromVirtualURL();
1298 rPar
.Get(0)->PutString( aStr
);
1301 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1309 if ( rPar
.Count() != 2 )
1310 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1313 SbxDataType eType
= rPar
.Get(1)->GetType();
1369 nLen
= (INT16
)rPar
.Get(1)->GetString().Len();
1375 rPar
.Get(0)->PutInteger( nLen
);
1380 // Uno-Struct eines beliebigen Typs erzeugen
1381 // 1. Parameter == Klassename, weitere Parameter zur Initialisierung
1382 RTLFUNC(CreateUnoStruct
)
1387 RTL_Impl_CreateUnoStruct( pBasic
, rPar
, bWrite
);
1390 // Uno-Service erzeugen
1391 // 1. Parameter == Service-Name
1392 RTLFUNC(CreateUnoService
)
1397 RTL_Impl_CreateUnoService( pBasic
, rPar
, bWrite
);
1400 RTLFUNC(CreateUnoServiceWithArguments
)
1405 RTL_Impl_CreateUnoServiceWithArguments( pBasic
, rPar
, bWrite
);
1409 RTLFUNC(CreateUnoValue
)
1414 RTL_Impl_CreateUnoValue( pBasic
, rPar
, bWrite
);
1418 // ServiceManager liefern (keine Parameter)
1419 RTLFUNC(GetProcessServiceManager
)
1424 RTL_Impl_GetProcessServiceManager( pBasic
, rPar
, bWrite
);
1427 // PropertySet erzeugen
1428 // 1. Parameter == Sequence<PropertyValue>
1429 RTLFUNC(CreatePropertySet
)
1434 RTL_Impl_CreatePropertySet( pBasic
, rPar
, bWrite
);
1437 // Abfragen, ob ein Interface unterstuetzt wird
1438 // Mehrere Interface-Namen als Parameter
1439 RTLFUNC(HasUnoInterfaces
)
1444 RTL_Impl_HasInterfaces( pBasic
, rPar
, bWrite
);
1447 // Abfragen, ob ein Basic-Objekt ein Uno-Struct repraesentiert
1448 RTLFUNC(IsUnoStruct
)
1453 RTL_Impl_IsUnoStruct( pBasic
, rPar
, bWrite
);
1456 // Abfragen, ob zwei Uno-Objekte identisch sind
1457 RTLFUNC(EqualUnoObjects
)
1462 RTL_Impl_EqualUnoObjects( pBasic
, rPar
, bWrite
);
1465 // Instanciate "com.sun.star.awt.UnoControlDialog" on basis
1466 // of a DialogLibrary entry: Convert from XML-ByteSequence
1467 // and attach events. Implemented in classes\eventatt.cxx
1468 void RTL_Impl_CreateUnoDialog( StarBASIC
* pBasic
, SbxArray
& rPar
, BOOL bWrite
);
1470 RTLFUNC(CreateUnoDialog
)
1475 RTL_Impl_CreateUnoDialog( pBasic
, rPar
, bWrite
);
1478 // Return the application standard lib as root scope
1479 RTLFUNC(GlobalScope
)
1484 SbxObject
* p
= pBasic
;
1485 while( p
->GetParent() )
1488 SbxVariableRef refVar
= rPar
.Get(0);
1489 refVar
->PutObject( p
);
1492 // Helper functions to convert Url from/to system paths
1493 RTLFUNC(ConvertToUrl
)
1498 if ( rPar
.Count() == 2 )
1500 String aStr
= rPar
.Get(1)->GetString();
1501 INetURLObject
aURLObj( aStr
, INET_PROT_FILE
);
1502 ::rtl::OUString aFileURL
= aURLObj
.GetMainURL( INetURLObject::NO_DECODE
);
1503 if( !aFileURL
.getLength() )
1504 ::osl::File::getFileURLFromSystemPath( aFileURL
, aFileURL
);
1505 if( !aFileURL
.getLength() )
1507 rPar
.Get(0)->PutString( String(aFileURL
) );
1510 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1513 RTLFUNC(ConvertFromUrl
)
1518 if ( rPar
.Count() == 2 )
1520 String aStr
= rPar
.Get(1)->GetString();
1521 ::rtl::OUString aSysPath
;
1522 ::osl::File::getSystemPathFromFileURL( aStr
, aSysPath
);
1523 if( !aSysPath
.getLength() )
1525 rPar
.Get(0)->PutString( String(aSysPath
) );
1528 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1532 // Provide DefaultContext
1533 RTLFUNC(GetDefaultContext
)
1538 RTL_Impl_GetDefaultContext( pBasic
, rPar
, bWrite
);
1547 USHORT nParCount
= rPar
.Count();
1548 if ( nParCount
!= 3 && nParCount
!= 2 )
1550 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1553 SbxBase
* pParObj
= rPar
.Get(1)->GetObject();
1554 SbxDimArray
* pArr
= PTR_CAST(SbxDimArray
,pParObj
);
1557 if( pArr
->GetDims() != 1 )
1558 StarBASIC::Error( SbERR_WRONG_DIMS
); // Syntax Error?!
1561 if( nParCount
== 3 )
1562 aDelim
= rPar
.Get(2)->GetString();
1564 aDelim
= String::CreateFromAscii( " " );
1567 short nLower
, nUpper
;
1568 pArr
->GetDim( 1, nLower
, nUpper
);
1569 for( short i
= nLower
; i
<= nUpper
; ++i
)
1571 String aStr
= pArr
->Get( &i
)->GetString();
1576 rPar
.Get(0)->PutString( aRetStr
);
1579 StarBASIC::Error( SbERR_MUST_HAVE_DIMS
);
1583 typedef ::std::vector
< String
> StringVector
;
1590 USHORT nParCount
= rPar
.Count();
1591 if ( nParCount
< 2 )
1593 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1597 String aExpression
= rPar
.Get(1)->GetString();
1598 short nArraySize
= 0;
1600 if( aExpression
.Len() )
1603 if( nParCount
>= 3 )
1604 aDelim
= rPar
.Get(2)->GetString();
1606 aDelim
= String::CreateFromAscii( " " );
1609 if( nParCount
== 4 )
1610 nCount
= rPar
.Get(3)->GetLong();
1612 xub_StrLen nDelimLen
= aDelim
.Len();
1615 xub_StrLen iSearch
= STRING_NOTFOUND
;
1616 xub_StrLen iStart
= 0;
1619 bool bBreak
= false;
1620 if( nCount
>= 0 && nArraySize
== nCount
- 1 )
1623 iSearch
= aExpression
.Search( aDelim
, iStart
);
1625 if( iSearch
!= STRING_NOTFOUND
&& !bBreak
)
1627 aSubStr
= aExpression
.Copy( iStart
, iSearch
- iStart
);
1628 iStart
= iSearch
+ nDelimLen
;
1632 aSubStr
= aExpression
.Copy( iStart
);
1634 vRet
.push_back( aSubStr
);
1640 while( iSearch
!= STRING_NOTFOUND
);
1644 vRet
.push_back( aExpression
);
1649 SbxDimArray
* pArray
= new SbxDimArray( SbxVARIANT
);
1650 pArray
->unoAddDim( 0, nArraySize
-1 );
1652 // Parameter ins Array uebernehmen
1653 for( short i
= 0 ; i
< nArraySize
; i
++ )
1655 SbxVariableRef xVar
= new SbxVariable( SbxVARIANT
);
1656 xVar
->PutString( vRet
[i
] );
1657 pArray
->Put( (SbxVariable
*)xVar
, &i
);
1660 // Array zurueckliefern
1661 SbxVariableRef refVar
= rPar
.Get(0);
1662 USHORT nFlags
= refVar
->GetFlags();
1663 refVar
->ResetFlag( SBX_FIXED
);
1664 refVar
->PutObject( pArray
);
1665 refVar
->SetFlags( nFlags
);
1666 refVar
->SetParameters( NULL
);
1669 // MonthName(month[, abbreviate])
1675 USHORT nParCount
= rPar
.Count();
1676 if( nParCount
!= 2 && nParCount
!= 3 )
1678 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1682 Reference
< XCalendar
> xCalendar
= getLocaleCalendar();
1683 if( !xCalendar
.is() )
1685 StarBASIC::Error( SbERR_INTERNAL_ERROR
);
1688 Sequence
< CalendarItem
> aMonthSeq
= xCalendar
->getMonths();
1689 sal_Int32 nMonthCount
= aMonthSeq
.getLength();
1691 INT16 nVal
= rPar
.Get(1)->GetInteger();
1692 if( nVal
< 1 || nVal
> nMonthCount
)
1694 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1698 BOOL bAbbreviate
= false;
1699 if( nParCount
== 3 )
1700 bAbbreviate
= rPar
.Get(2)->GetBool();
1702 const CalendarItem
* pCalendarItems
= aMonthSeq
.getConstArray();
1703 const CalendarItem
& rItem
= pCalendarItems
[nVal
- 1];
1705 ::rtl::OUString aRetStr
= ( bAbbreviate
? rItem
.AbbrevName
: rItem
.FullName
);
1706 rPar
.Get(0)->PutString( String(aRetStr
) );
1709 // WeekdayName(weekday, abbreviate, firstdayofweek)
1710 RTLFUNC(WeekdayName
)
1715 USHORT nParCount
= rPar
.Count();
1716 if( nParCount
< 2 || nParCount
> 4 )
1718 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1722 Reference
< XCalendar
> xCalendar
= getLocaleCalendar();
1723 if( !xCalendar
.is() )
1725 StarBASIC::Error( SbERR_INTERNAL_ERROR
);
1729 Sequence
< CalendarItem
> aDaySeq
= xCalendar
->getDays();
1730 INT16 nDayCount
= (INT16
)aDaySeq
.getLength();
1731 INT16 nDay
= rPar
.Get(1)->GetInteger();
1732 INT16 nFirstDay
= 0;
1733 if( nParCount
== 4 )
1735 nFirstDay
= rPar
.Get(3)->GetInteger();
1736 if( nFirstDay
< 0 || nFirstDay
> 7 )
1738 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1742 if( nFirstDay
== 0 )
1743 nFirstDay
= INT16( xCalendar
->getFirstDayOfWeek() + 1 );
1745 nDay
= 1 + (nDay
+ nDayCount
+ nFirstDay
- 2) % nDayCount
;
1746 if( nDay
< 1 || nDay
> nDayCount
)
1748 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1752 BOOL bAbbreviate
= false;
1753 if( nParCount
>= 3 )
1755 SbxVariable
* pPar2
= rPar
.Get(2);
1756 if( !pPar2
->IsErr() )
1757 bAbbreviate
= pPar2
->GetBool();
1760 const CalendarItem
* pCalendarItems
= aDaySeq
.getConstArray();
1761 const CalendarItem
& rItem
= pCalendarItems
[nDay
- 1];
1763 ::rtl::OUString aRetStr
= ( bAbbreviate
? rItem
.AbbrevName
: rItem
.FullName
);
1764 rPar
.Get(0)->PutString( String(aRetStr
) );
1767 INT16
implGetWeekDay( double aDate
, bool bFirstDayParam
= false, INT16 nFirstDay
= 0 )
1769 Date
aRefDate( 1,1,1900 );
1770 long nDays
= (long) aDate
;
1771 nDays
-= 2; // normieren: 1.1.1900 => 0
1773 DayOfWeek aDay
= aRefDate
.GetDayOfWeek();
1775 if ( aDay
!= SUNDAY
)
1776 nDay
= (INT16
)aDay
+ 2;
1778 nDay
= 1; // 1==Sonntag
1780 // #117253 Optional 2. parameter "firstdayofweek"
1781 if( bFirstDayParam
)
1783 if( nFirstDay
< 0 || nFirstDay
> 7 )
1785 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1788 if( nFirstDay
== 0 )
1790 Reference
< XCalendar
> xCalendar
= getLocaleCalendar();
1791 if( !xCalendar
.is() )
1793 StarBASIC::Error( SbERR_INTERNAL_ERROR
);
1796 nFirstDay
= INT16( xCalendar
->getFirstDayOfWeek() + 1 );
1798 nDay
= 1 + (nDay
+ 7 - nFirstDay
) % 7;
1808 USHORT nParCount
= rPar
.Count();
1809 if ( nParCount
< 2 )
1810 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1813 double aDate
= rPar
.Get(1)->GetDate();
1815 bool bFirstDay
= false;
1816 INT16 nFirstDay
= 0;
1817 if ( nParCount
> 2 )
1819 nFirstDay
= rPar
.Get(2)->GetInteger();
1822 INT16 nDay
= implGetWeekDay( aDate
, bFirstDay
, nFirstDay
);
1823 rPar
.Get(0)->PutInteger( nDay
);
1845 Interval meInterval
;
1846 const char* mpStringCode
;
1850 IntervalInfo( Interval eInterval
, const char* pStringCode
, double dValue
, bool bSimple
)
1851 : meInterval( eInterval
)
1852 , mpStringCode( pStringCode
)
1854 , mbSimple( bSimple
)
1858 static IntervalInfo pIntervalTable
[] =
1860 IntervalInfo( INTERVAL_YYYY
, "yyyy", 0.0, false ), // Year
1861 IntervalInfo( INTERVAL_Q
, "q", 0.0, false ), // Quarter
1862 IntervalInfo( INTERVAL_M
, "m", 0.0, false ), // Month
1863 IntervalInfo( INTERVAL_Y
, "y", 1.0, true ), // Day of year
1864 IntervalInfo( INTERVAL_D
, "d", 1.0, true ), // Day
1865 IntervalInfo( INTERVAL_W
, "w", 1.0, true ), // Weekday
1866 IntervalInfo( INTERVAL_WW
, "ww", 7.0, true ), // Week
1867 IntervalInfo( INTERVAL_H
, "h", (1.0 / 24.0), true ), // Hour
1868 IntervalInfo( INTERVAL_N
, "n", (1.0 / 1440.0), true), // Minute
1869 IntervalInfo( INTERVAL_S
, "s", (1.0 / 86400.0), true ), // Second
1870 IntervalInfo( INTERVAL_NONE
, NULL
, 0.0, false )
1873 IntervalInfo
* getIntervalInfo( const String
& rStringCode
)
1875 IntervalInfo
* pInfo
= NULL
;
1877 while( (pInfo
= pIntervalTable
+ i
)->mpStringCode
!= NULL
)
1879 if( rStringCode
.EqualsIgnoreCaseAscii( pInfo
->mpStringCode
) )
1887 BOOL
implDateSerial( INT16 nYear
, INT16 nMonth
, INT16 nDay
, double& rdRet
);
1888 INT16
implGetDateDay( double aDate
);
1889 INT16
implGetDateMonth( double aDate
);
1890 INT16
implGetDateYear( double aDate
);
1892 INT16
implGetHour( double dDate
);
1893 INT16
implGetMinute( double dDate
);
1894 INT16
implGetSecond( double dDate
);
1897 inline void implGetDayMonthYear( INT16
& rnYear
, INT16
& rnMonth
, INT16
& rnDay
, double dDate
)
1899 rnDay
= implGetDateDay( dDate
);
1900 rnMonth
= implGetDateMonth( dDate
);
1901 rnYear
= implGetDateYear( dDate
);
1904 inline INT16
limitToINT16( INT32 n32
)
1908 else if( n32
< -32768 )
1918 USHORT nParCount
= rPar
.Count();
1919 if( nParCount
!= 4 )
1921 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1925 String aStringCode
= rPar
.Get(1)->GetString();
1926 IntervalInfo
* pInfo
= getIntervalInfo( aStringCode
);
1929 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
1933 INT32 lNumber
= rPar
.Get(2)->GetLong();
1934 double dDate
= rPar
.Get(3)->GetDate();
1935 double dNewDate
= 0;
1936 if( pInfo
->mbSimple
)
1938 double dAdd
= pInfo
->mdValue
* lNumber
;
1939 dNewDate
= dDate
+ dAdd
;
1943 // Keep hours, minutes, seconds
1944 double dHoursMinutesSeconds
= dDate
- floor( dDate
);
1947 INT16 nYear
, nMonth
, nDay
;
1948 INT16 nTargetYear16
= 0, nTargetMonth
= 0;
1949 implGetDayMonthYear( nYear
, nMonth
, nDay
, dDate
);
1950 switch( pInfo
->meInterval
)
1954 INT32 nTargetYear
= lNumber
+ nYear
;
1955 nTargetYear16
= limitToINT16( nTargetYear
);
1956 nTargetMonth
= nMonth
;
1957 bOk
= implDateSerial( nTargetYear16
, nTargetMonth
, nDay
, dNewDate
);
1963 bool bNeg
= (lNumber
< 0);
1968 if( pInfo
->meInterval
== INTERVAL_Q
)
1970 nYearsAdd
= lNumber
/ 4;
1971 nMonthAdd
= (INT16
)( 3 * (lNumber
% 4) );
1975 nYearsAdd
= lNumber
/ 12;
1976 nMonthAdd
= (INT16
)( lNumber
% 12 );
1982 nTargetMonth
= nMonth
- nMonthAdd
;
1983 if( nTargetMonth
<= 0 )
1988 nTargetYear
= (INT32
)nYear
- nYearsAdd
;
1992 nTargetMonth
= nMonth
+ nMonthAdd
;
1993 if( nTargetMonth
> 12 )
1998 nTargetYear
= (INT32
)nYear
+ nYearsAdd
;
2000 nTargetYear16
= limitToINT16( nTargetYear
);
2001 bOk
= implDateSerial( nTargetYear16
, nTargetMonth
, nDay
, dNewDate
);
2010 INT16 nNewYear
, nNewMonth
, nNewDay
;
2011 implGetDayMonthYear( nNewYear
, nNewMonth
, nNewDay
, dNewDate
);
2012 if( nNewYear
> 9999 || nNewYear
< 100 )
2014 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2017 INT16 nCorrectionDay
= nDay
;
2018 while( nNewMonth
> nTargetMonth
)
2021 implDateSerial( nTargetYear16
, nTargetMonth
, nCorrectionDay
, dNewDate
);
2022 implGetDayMonthYear( nNewYear
, nNewMonth
, nNewDay
, dNewDate
);
2024 dNewDate
+= dHoursMinutesSeconds
;
2028 rPar
.Get(0)->PutDate( dNewDate
);
2031 inline double RoundImpl( double d
)
2033 return ( d
>= 0 ) ? floor( d
+ 0.5 ) : -floor( -d
+ 0.5 );
2041 // DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
2043 USHORT nParCount
= rPar
.Count();
2044 if( nParCount
< 4 || nParCount
> 6 )
2046 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2050 String aStringCode
= rPar
.Get(1)->GetString();
2051 IntervalInfo
* pInfo
= getIntervalInfo( aStringCode
);
2054 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2058 double dDate1
= rPar
.Get(2)->GetDate();
2059 double dDate2
= rPar
.Get(3)->GetDate();
2062 switch( pInfo
->meInterval
)
2066 INT16 nYear1
= implGetDateYear( dDate1
);
2067 INT16 nYear2
= implGetDateYear( dDate2
);
2068 dRet
= nYear2
- nYear1
;
2073 INT16 nYear1
= implGetDateYear( dDate1
);
2074 INT16 nYear2
= implGetDateYear( dDate2
);
2075 INT16 nQ1
= 1 + (implGetDateMonth( dDate1
) - 1) / 3;
2076 INT16 nQ2
= 1 + (implGetDateMonth( dDate2
) - 1) / 3;
2077 INT16 nQGes1
= 4 * nYear1
+ nQ1
;
2078 INT16 nQGes2
= 4 * nYear2
+ nQ2
;
2079 dRet
= nQGes2
- nQGes1
;
2084 INT16 nYear1
= implGetDateYear( dDate1
);
2085 INT16 nYear2
= implGetDateYear( dDate2
);
2086 INT16 nMonth1
= implGetDateMonth( dDate1
);
2087 INT16 nMonth2
= implGetDateMonth( dDate2
);
2088 INT16 nMonthGes1
= 12 * nYear1
+ nMonth1
;
2089 INT16 nMonthGes2
= 12 * nYear2
+ nMonth2
;
2090 dRet
= nMonthGes2
- nMonthGes1
;
2096 double dDays1
= floor( dDate1
);
2097 double dDays2
= floor( dDate2
);
2098 dRet
= dDays2
- dDays1
;
2104 double dDays1
= floor( dDate1
);
2105 double dDays2
= floor( dDate2
);
2106 if( pInfo
->meInterval
== INTERVAL_WW
)
2108 INT16 nFirstDay
= 1; // Default
2109 if( nParCount
>= 5 )
2111 nFirstDay
= rPar
.Get(4)->GetInteger();
2112 if( nFirstDay
< 0 || nFirstDay
> 7 )
2114 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2117 if( nFirstDay
== 0 )
2119 Reference
< XCalendar
> xCalendar
= getLocaleCalendar();
2120 if( !xCalendar
.is() )
2122 StarBASIC::Error( SbERR_INTERNAL_ERROR
);
2125 nFirstDay
= INT16( xCalendar
->getFirstDayOfWeek() + 1 );
2128 INT16 nDay1
= implGetWeekDay( dDate1
);
2129 INT16 nDay1_Diff
= nDay1
- nFirstDay
;
2130 if( nDay1_Diff
< 0 )
2132 dDays1
-= nDay1_Diff
;
2134 INT16 nDay2
= implGetWeekDay( dDate2
);
2135 INT16 nDay2_Diff
= nDay2
- nFirstDay
;
2136 if( nDay2_Diff
< 0 )
2138 dDays2
-= nDay2_Diff
;
2141 double dDiff
= dDays2
- dDays1
;
2142 dRet
= ( dDiff
>= 0 ) ? floor( dDiff
/ 7.0 ) : -floor( -dDiff
/ 7.0 );
2147 double dFactor
= 24.0;
2148 dRet
= RoundImpl( dFactor
* (dDate2
- dDate1
) );
2153 double dFactor
=1440.0;
2154 dRet
= RoundImpl( dFactor
* (dDate2
- dDate1
) );
2159 double dFactor
= 86400.0;
2160 dRet
= RoundImpl( dFactor
* (dDate2
- dDate1
) );
2166 rPar
.Get(0)->PutDouble( dRet
);
2169 double implGetDateOfFirstDayInFirstWeek
2170 ( INT16 nYear
, INT16
& nFirstDay
, INT16
& nFirstWeek
, bool* pbError
= NULL
)
2173 if( nFirstDay
< 0 || nFirstDay
> 7 )
2174 nError
= SbERR_BAD_ARGUMENT
;
2176 if( nFirstWeek
< 0 || nFirstWeek
> 3 )
2177 nError
= SbERR_BAD_ARGUMENT
;
2179 Reference
< XCalendar
> xCalendar
;
2180 if( nFirstDay
== 0 || nFirstWeek
== 0 )
2182 xCalendar
= getLocaleCalendar();
2183 if( !xCalendar
.is() )
2184 nError
= SbERR_BAD_ARGUMENT
;
2189 StarBASIC::Error( nError
);
2195 if( nFirstDay
== 0 )
2196 nFirstDay
= INT16( xCalendar
->getFirstDayOfWeek() + 1 );
2198 INT16 nFirstWeekMinDays
= 0; // Not used for vbFirstJan1 = default
2199 if( nFirstWeek
== 0 )
2201 nFirstWeekMinDays
= xCalendar
->getMinimumNumberOfDaysForFirstWeek();
2202 if( nFirstWeekMinDays
== 1 )
2204 nFirstWeekMinDays
= 0;
2207 else if( nFirstWeekMinDays
== 4 )
2209 else if( nFirstWeekMinDays
== 7 )
2212 else if( nFirstWeek
== 2 )
2213 nFirstWeekMinDays
= 4; // vbFirstFourDays
2214 else if( nFirstWeek
== 3 )
2215 nFirstWeekMinDays
= 7; // vbFirstFourDays
2218 implDateSerial( nYear
, 1, 1, dBaseDate
);
2219 double dRetDate
= dBaseDate
;
2221 INT16 nWeekDay0101
= implGetWeekDay( dBaseDate
);
2222 INT16 nDayDiff
= nWeekDay0101
- nFirstDay
;
2226 if( nFirstWeekMinDays
)
2228 INT16 nThisWeeksDaysInYearCount
= 7 - nDayDiff
;
2229 if( nThisWeeksDaysInYearCount
< nFirstWeekMinDays
)
2232 dRetDate
= dBaseDate
- nDayDiff
;
2241 // DatePart(interval, date[,firstdayofweek[, firstweekofyear]])
2243 USHORT nParCount
= rPar
.Count();
2244 if( nParCount
< 3 || nParCount
> 5 )
2246 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2250 String aStringCode
= rPar
.Get(1)->GetString();
2251 IntervalInfo
* pInfo
= getIntervalInfo( aStringCode
);
2254 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2258 double dDate
= rPar
.Get(2)->GetDate();
2261 switch( pInfo
->meInterval
)
2265 nRet
= implGetDateYear( dDate
);
2270 nRet
= 1 + (implGetDateMonth( dDate
) - 1) / 3;
2275 nRet
= implGetDateMonth( dDate
);
2280 INT16 nYear
= implGetDateYear( dDate
);
2282 implDateSerial( nYear
, 1, 1, dBaseDate
);
2283 nRet
= 1 + INT32( dDate
- dBaseDate
);
2288 nRet
= implGetDateDay( dDate
);
2293 bool bFirstDay
= false;
2294 INT16 nFirstDay
= 1; // Default
2295 if( nParCount
>= 4 )
2297 nFirstDay
= rPar
.Get(3)->GetInteger();
2300 nRet
= implGetWeekDay( dDate
, bFirstDay
, nFirstDay
);
2305 INT16 nFirstDay
= 1; // Default
2306 if( nParCount
>= 4 )
2307 nFirstDay
= rPar
.Get(3)->GetInteger();
2309 INT16 nFirstWeek
= 1; // Default
2310 if( nParCount
== 5 )
2311 nFirstWeek
= rPar
.Get(4)->GetInteger();
2313 INT16 nYear
= implGetDateYear( dDate
);
2314 bool bError
= false;
2315 double dYearFirstDay
= implGetDateOfFirstDayInFirstWeek( nYear
, nFirstDay
, nFirstWeek
, &bError
);
2318 if( dYearFirstDay
> dDate
)
2320 // Date belongs to last year's week
2321 dYearFirstDay
= implGetDateOfFirstDayInFirstWeek( nYear
- 1, nFirstDay
, nFirstWeek
);
2323 else if( nFirstWeek
!= 1 )
2325 // Check if date belongs to next year
2326 double dNextYearFirstDay
= implGetDateOfFirstDayInFirstWeek( nYear
+ 1, nFirstDay
, nFirstWeek
);
2327 if( dDate
>= dNextYearFirstDay
)
2328 dYearFirstDay
= dNextYearFirstDay
;
2332 double dDiff
= dDate
- dYearFirstDay
;
2333 nRet
= 1 + INT32( dDiff
/ 7 );
2339 nRet
= implGetHour( dDate
);
2344 nRet
= implGetMinute( dDate
);
2349 nRet
= implGetSecond( dDate
);
2355 rPar
.Get(0)->PutLong( nRet
);
2358 // FormatDateTime(Date[,NamedFormat])
2359 RTLFUNC(FormatDateTime
)
2364 USHORT nParCount
= rPar
.Count();
2365 if( nParCount
< 2 || nParCount
> 3 )
2367 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2371 double dDate
= rPar
.Get(1)->GetDate();
2372 INT16 nNamedFormat
= 0;
2375 nNamedFormat
= rPar
.Get(2)->GetInteger();
2376 if( nNamedFormat
< 0 || nNamedFormat
> 4 )
2378 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2383 Reference
< XCalendar
> xCalendar
= getLocaleCalendar();
2384 if( !xCalendar
.is() )
2386 StarBASIC::Error( SbERR_INTERNAL_ERROR
);
2391 SbxVariableRef pSbxVar
= new SbxVariable( SbxSTRING
);
2392 switch( nNamedFormat
)
2395 // Display a date and/or time. If there is a date part,
2396 // display it as a short date. If there is a time part,
2397 // display it as a long time. If present, both parts are displayed.
2399 // 12/21/2004 11:24:50 AM
2400 // 21.12.2004 12:13:51
2402 pSbxVar
->PutDate( dDate
);
2403 aRetStr
= pSbxVar
->GetString();
2406 // LongDate: Display a date using the long date format specified
2407 // in your computer's regional settings.
2408 // Tuesday, December 21, 2004
2409 // Dienstag, 21. December 2004
2412 SvNumberFormatter
* pFormatter
= NULL
;
2414 pFormatter
= pINST
->GetNumberFormatter();
2417 sal_uInt32 n
; // Dummy
2418 SbiInstance::PrepareNumberFormatter( pFormatter
, n
, n
, n
);
2421 LanguageType eLangType
= GetpApp()->GetSettings().GetLanguage();
2422 ULONG nIndex
= pFormatter
->GetFormatIndex( NF_DATE_SYSTEM_LONG
, eLangType
);
2424 pFormatter
->GetOutputString( dDate
, nIndex
, aRetStr
, &pCol
);
2432 // ShortDate: Display a date using the short date format specified
2433 // in your computer's regional settings.
2437 pSbxVar
->PutDate( floor(dDate
) );
2438 aRetStr
= pSbxVar
->GetString();
2441 // LongTime: Display a time using the time format specified
2442 // in your computer's regional settings.
2446 // ShortTime: Display a time using the 24-hour format (hh:mm).
2450 double dTime
= modf( dDate
, &n
);
2451 pSbxVar
->PutDate( dTime
);
2452 if( nNamedFormat
== 3 )
2453 aRetStr
= pSbxVar
->GetString();
2455 aRetStr
= pSbxVar
->GetString().Copy( 0, 5 );
2459 rPar
.Get(0)->PutString( aRetStr
);
2467 USHORT nParCount
= rPar
.Count();
2468 if( nParCount
!= 2 && nParCount
!= 3 )
2470 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2474 SbxVariable
*pSbxVariable
= rPar
.Get(1);
2475 double dVal
= pSbxVariable
->GetDouble();
2486 INT16 numdecimalplaces
= 0;
2487 if( nParCount
== 3 )
2489 numdecimalplaces
= rPar
.Get(2)->GetInteger();
2490 if( numdecimalplaces
< 0 || numdecimalplaces
> 22 )
2492 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2497 if( numdecimalplaces
== 0 )
2499 dRes
= floor( dVal
+ 0.5 );
2503 double dFactor
= pow( 10.0, numdecimalplaces
);
2505 dRes
= floor( dVal
+ 0.5 );
2512 rPar
.Get(0)->PutDouble( dRes
);
2515 void CallFunctionAccessFunction( const Sequence
< Any
>& aArgs
, const rtl::OUString
& sFuncName
, SbxVariable
* pRet
)
2517 static Reference
< XFunctionAccess
> xFunc
;
2523 Reference
< XMultiServiceFactory
> xFactory( getProcessServiceFactory() );
2526 xFunc
.set( xFactory
->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.sheet.FunctionAccess")), UNO_QUERY_THROW
);
2529 Any aRet
= xFunc
->callFunction( sFuncName
, aArgs
);
2531 unoToSbxValue( pRet
, aRet
);
2536 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2545 ULONG nArgCount
= rPar
.Count()-1;
2547 if ( nArgCount
< 4 )
2549 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2553 // retrieve non-optional params
2555 Sequence
< Any
> aParams( 4 );
2556 aParams
[ 0 ] <<= makeAny( rPar
.Get(1)->GetDouble() );
2557 aParams
[ 1 ] <<= makeAny( rPar
.Get(2)->GetDouble() );
2558 aParams
[ 2 ] <<= makeAny( rPar
.Get(3)->GetDouble() );
2559 aParams
[ 3 ] <<= makeAny( rPar
.Get(4)->GetDouble() );
2561 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SYD") ), rPar
.Get( 0 ) );
2569 ULONG nArgCount
= rPar
.Count()-1;
2571 if ( nArgCount
< 3 )
2573 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2577 // retrieve non-optional params
2579 Sequence
< Any
> aParams( 3 );
2580 aParams
[ 0 ] <<= makeAny( rPar
.Get(1)->GetDouble() );
2581 aParams
[ 1 ] <<= makeAny( rPar
.Get(2)->GetDouble() );
2582 aParams
[ 2 ] <<= makeAny( rPar
.Get(3)->GetDouble() );
2584 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SLN") ), rPar
.Get( 0 ) );
2592 ULONG nArgCount
= rPar
.Count()-1;
2594 if ( nArgCount
< 3 || nArgCount
> 5 )
2596 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2599 // retrieve non-optional params
2601 double rate
= rPar
.Get(1)->GetDouble();
2602 double nper
= rPar
.Get(2)->GetDouble();
2603 double pmt
= rPar
.Get(3)->GetDouble();
2605 // set default values for Optional args
2610 if ( nArgCount
>= 4 )
2612 if( rPar
.Get(4)->GetType() != SbxEMPTY
)
2613 fv
= rPar
.Get(4)->GetDouble();
2616 if ( nArgCount
>= 5 )
2618 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
2619 type
= rPar
.Get(5)->GetDouble();
2622 Sequence
< Any
> aParams( 5 );
2623 aParams
[ 0 ] <<= rate
;
2624 aParams
[ 1 ] <<= nper
;
2625 aParams
[ 2 ] <<= pmt
;
2626 aParams
[ 3 ] <<= fv
;
2627 aParams
[ 4 ] <<= type
;
2629 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Pmt") ), rPar
.Get( 0 ) );
2637 ULONG nArgCount
= rPar
.Count()-1;
2639 if ( nArgCount
< 4 || nArgCount
> 6 )
2641 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2644 // retrieve non-optional params
2646 double rate
= rPar
.Get(1)->GetDouble();
2647 double per
= rPar
.Get(2)->GetDouble();
2648 double nper
= rPar
.Get(3)->GetDouble();
2649 double pv
= rPar
.Get(4)->GetDouble();
2651 // set default values for Optional args
2656 if ( nArgCount
>= 5 )
2658 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
2659 fv
= rPar
.Get(5)->GetDouble();
2662 if ( nArgCount
>= 6 )
2664 if( rPar
.Get(6)->GetType() != SbxEMPTY
)
2665 type
= rPar
.Get(6)->GetDouble();
2668 Sequence
< Any
> aParams( 6 );
2669 aParams
[ 0 ] <<= rate
;
2670 aParams
[ 1 ] <<= per
;
2671 aParams
[ 2 ] <<= nper
;
2672 aParams
[ 3 ] <<= pv
;
2673 aParams
[ 4 ] <<= fv
;
2674 aParams
[ 5 ] <<= type
;
2676 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PPmt") ), rPar
.Get( 0 ) );
2684 ULONG nArgCount
= rPar
.Count()-1;
2686 if ( nArgCount
< 3 || nArgCount
> 5 )
2688 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2691 // retrieve non-optional params
2693 double rate
= rPar
.Get(1)->GetDouble();
2694 double nper
= rPar
.Get(2)->GetDouble();
2695 double pmt
= rPar
.Get(3)->GetDouble();
2697 // set default values for Optional args
2702 if ( nArgCount
>= 4 )
2704 if( rPar
.Get(4)->GetType() != SbxEMPTY
)
2705 fv
= rPar
.Get(4)->GetDouble();
2708 if ( nArgCount
>= 5 )
2710 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
2711 type
= rPar
.Get(5)->GetDouble();
2714 Sequence
< Any
> aParams( 5 );
2715 aParams
[ 0 ] <<= rate
;
2716 aParams
[ 1 ] <<= nper
;
2717 aParams
[ 2 ] <<= pmt
;
2718 aParams
[ 3 ] <<= fv
;
2719 aParams
[ 4 ] <<= type
;
2721 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PV") ), rPar
.Get( 0 ) );
2729 ULONG nArgCount
= rPar
.Count()-1;
2731 if ( nArgCount
< 1 || nArgCount
> 2 )
2733 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2737 Sequence
< Any
> aParams( 2 );
2738 aParams
[ 0 ] <<= makeAny( rPar
.Get(1)->GetDouble() );
2739 Any aValues
= sbxToUnoValue( rPar
.Get(2),
2740 getCppuType( (Sequence
<double>*)0 ) );
2742 // convert for calc functions
2743 Sequence
< Sequence
< double > > sValues(1);
2744 aValues
>>= sValues
[ 0 ];
2745 aValues
<<= sValues
;
2747 aParams
[ 1 ] <<= aValues
;
2749 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NPV") ), rPar
.Get( 0 ) );
2757 ULONG nArgCount
= rPar
.Count()-1;
2759 if ( nArgCount
< 3 || nArgCount
> 5 )
2761 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2764 // retrieve non-optional params
2766 double rate
= rPar
.Get(1)->GetDouble();
2767 double pmt
= rPar
.Get(2)->GetDouble();
2768 double pv
= rPar
.Get(3)->GetDouble();
2770 // set default values for Optional args
2775 if ( nArgCount
>= 4 )
2777 if( rPar
.Get(4)->GetType() != SbxEMPTY
)
2778 fv
= rPar
.Get(4)->GetDouble();
2781 if ( nArgCount
>= 5 )
2783 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
2784 type
= rPar
.Get(5)->GetDouble();
2787 Sequence
< Any
> aParams( 5 );
2788 aParams
[ 0 ] <<= rate
;
2789 aParams
[ 1 ] <<= pmt
;
2790 aParams
[ 2 ] <<= pv
;
2791 aParams
[ 3 ] <<= fv
;
2792 aParams
[ 4 ] <<= type
;
2794 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NPer") ), rPar
.Get( 0 ) );
2802 ULONG nArgCount
= rPar
.Count()-1;
2804 if ( nArgCount
< 3 )
2806 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2810 // retrieve non-optional params
2812 Sequence
< Any
> aParams( 3 );
2813 Any aValues
= sbxToUnoValue( rPar
.Get(1),
2814 getCppuType( (Sequence
<double>*)0 ) );
2816 // convert for calc functions
2817 Sequence
< Sequence
< double > > sValues(1);
2818 aValues
>>= sValues
[ 0 ];
2819 aValues
<<= sValues
;
2821 aParams
[ 0 ] <<= aValues
;
2822 aParams
[ 1 ] <<= makeAny( rPar
.Get(2)->GetDouble() );
2823 aParams
[ 2 ] <<= makeAny( rPar
.Get(3)->GetDouble() );
2825 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("MIRR") ), rPar
.Get( 0 ) );
2833 ULONG nArgCount
= rPar
.Count()-1;
2835 if ( nArgCount
< 1 || nArgCount
> 2 )
2837 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2840 // retrieve non-optional params
2841 Any aValues
= sbxToUnoValue( rPar
.Get(1),
2842 getCppuType( (Sequence
<double>*)0 ) );
2844 // convert for calc functions
2845 Sequence
< Sequence
< double > > sValues(1);
2846 aValues
>>= sValues
[ 0 ];
2847 aValues
<<= sValues
;
2849 // set default values for Optional args
2852 if ( nArgCount
>= 2 )
2854 if( rPar
.Get(2)->GetType() != SbxEMPTY
)
2855 guess
= rPar
.Get(2)->GetDouble();
2858 Sequence
< Any
> aParams( 2 );
2859 aParams
[ 0 ] <<= aValues
;
2860 aParams
[ 1 ] <<= guess
;
2862 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IRR") ), rPar
.Get( 0 ) );
2870 ULONG nArgCount
= rPar
.Count()-1;
2872 if ( nArgCount
< 4 || nArgCount
> 6 )
2874 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2877 // retrieve non-optional params
2879 double rate
= rPar
.Get(1)->GetDouble();
2880 double per
= rPar
.Get(2)->GetInteger();
2881 double nper
= rPar
.Get(3)->GetDouble();
2882 double pv
= rPar
.Get(4)->GetDouble();
2884 // set default values for Optional args
2889 if ( nArgCount
>= 5 )
2891 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
2892 fv
= rPar
.Get(5)->GetDouble();
2895 if ( nArgCount
>= 6 )
2897 if( rPar
.Get(6)->GetType() != SbxEMPTY
)
2898 type
= rPar
.Get(6)->GetDouble();
2901 Sequence
< Any
> aParams( 6 );
2902 aParams
[ 0 ] <<= rate
;
2903 aParams
[ 1 ] <<= per
;
2904 aParams
[ 2 ] <<= nper
;
2905 aParams
[ 3 ] <<= pv
;
2906 aParams
[ 4 ] <<= fv
;
2907 aParams
[ 5 ] <<= type
;
2909 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IPmt") ), rPar
.Get( 0 ) );
2917 ULONG nArgCount
= rPar
.Count()-1;
2919 if ( nArgCount
< 3 || nArgCount
> 5 )
2921 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2924 // retrieve non-optional params
2926 double rate
= rPar
.Get(1)->GetDouble();
2927 double nper
= rPar
.Get(2)->GetDouble();
2928 double pmt
= rPar
.Get(3)->GetDouble();
2930 // set default values for Optional args
2935 if ( nArgCount
>= 4 )
2937 if( rPar
.Get(4)->GetType() != SbxEMPTY
)
2938 pv
= rPar
.Get(4)->GetDouble();
2941 if ( nArgCount
>= 5 )
2943 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
2944 type
= rPar
.Get(5)->GetDouble();
2947 Sequence
< Any
> aParams( 5 );
2948 aParams
[ 0 ] <<= rate
;
2949 aParams
[ 1 ] <<= nper
;
2950 aParams
[ 2 ] <<= pmt
;
2951 aParams
[ 3 ] <<= pv
;
2952 aParams
[ 4 ] <<= type
;
2954 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FV") ), rPar
.Get( 0 ) );
2962 ULONG nArgCount
= rPar
.Count()-1;
2964 if ( nArgCount
< 4 || nArgCount
> 5 )
2966 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
2969 // retrieve non-optional params
2971 double cost
= rPar
.Get(1)->GetDouble();
2972 double salvage
= rPar
.Get(2)->GetDouble();
2973 double life
= rPar
.Get(3)->GetDouble();
2974 double period
= rPar
.Get(4)->GetDouble();
2976 // set default values for Optional args
2980 if ( nArgCount
>= 5 )
2982 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
2983 factor
= rPar
.Get(5)->GetDouble();
2986 Sequence
< Any
> aParams( 5 );
2987 aParams
[ 0 ] <<= cost
;
2988 aParams
[ 1 ] <<= salvage
;
2989 aParams
[ 2 ] <<= life
;
2990 aParams
[ 3 ] <<= period
;
2991 aParams
[ 4 ] <<= factor
;
2993 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DDB") ), rPar
.Get( 0 ) );
3001 ULONG nArgCount
= rPar
.Count()-1;
3003 if ( nArgCount
< 3 || nArgCount
> 6 )
3005 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
3008 // retrieve non-optional params
3014 nper
= rPar
.Get(1)->GetDouble();
3015 pmt
= rPar
.Get(2)->GetDouble();
3016 pv
= rPar
.Get(3)->GetDouble();
3018 // set default values for Optional args
3024 if ( nArgCount
>= 4 )
3026 if( rPar
.Get(4)->GetType() != SbxEMPTY
)
3027 fv
= rPar
.Get(4)->GetDouble();
3031 if ( nArgCount
>= 5 )
3033 if( rPar
.Get(5)->GetType() != SbxEMPTY
)
3034 type
= rPar
.Get(5)->GetDouble();
3038 if ( nArgCount
>= 6 )
3040 if( rPar
.Get(6)->GetType() != SbxEMPTY
)
3041 type
= rPar
.Get(6)->GetDouble();
3044 Sequence
< Any
> aParams( 6 );
3045 aParams
[ 0 ] <<= nper
;
3046 aParams
[ 1 ] <<= pmt
;
3047 aParams
[ 2 ] <<= pv
;
3048 aParams
[ 3 ] <<= fv
;
3049 aParams
[ 4 ] <<= type
;
3050 aParams
[ 5 ] <<= guess
;
3052 CallFunctionAccessFunction( aParams
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Rate") ), rPar
.Get( 0 ) );
3060 if ( rPar
.Count() != 2 )
3062 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
3066 SbxVariable
*pSbxVariable
= rPar
.Get(1);
3067 if( pSbxVariable
->IsNull() )
3069 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
3073 String aStr
= pSbxVariable
->GetString();
3075 rPar
.Get(0)->PutString( aStr
);
3078 RTLFUNC(CompatibilityMode
)
3083 bool bEnabled
= false;
3084 USHORT nCount
= rPar
.Count();
3085 if ( nCount
!= 1 && nCount
!= 2 )
3086 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
3088 SbiInstance
* pInst
= pINST
;
3092 pInst
->EnableCompatibility( rPar
.Get(1)->GetBool() );
3094 bEnabled
= pInst
->IsCompatibility();
3096 rPar
.Get(0)->PutBool( bEnabled
);
3104 // 2 parameters needed
3105 if ( rPar
.Count() < 3 )
3107 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
3111 USHORT nByteCount
= rPar
.Get(1)->GetUShort();
3112 INT16 nFileNumber
= rPar
.Get(2)->GetInteger();
3114 SbiIoSystem
* pIosys
= pINST
->GetIoSystem();
3115 SbiStream
* pSbStrm
= pIosys
->GetStream( nFileNumber
);
3116 if ( !pSbStrm
|| !(pSbStrm
->GetMode() & (SBSTRM_BINARY
| SBSTRM_INPUT
)) )
3118 StarBASIC::Error( SbERR_BAD_CHANNEL
);
3122 ByteString aByteBuffer
;
3123 SbError err
= pSbStrm
->Read( aByteBuffer
, nByteCount
, true );
3125 err
= pIosys
->GetError();
3129 StarBASIC::Error( err
);
3132 rPar
.Get(0)->PutString( String( aByteBuffer
, gsl_getSystemTextEncoding() ) );
3141 SbModule
* pActiveModule
= pINST
->GetActiveModule();
3142 SbClassModuleObject
* pClassModuleObject
= PTR_CAST(SbClassModuleObject
,pActiveModule
);
3143 SbxVariableRef refVar
= rPar
.Get(0);
3144 if( pClassModuleObject
== NULL
)
3146 SbObjModule
* pMod
= PTR_CAST(SbObjModule
,pActiveModule
);
3148 refVar
->PutObject( pMod
);
3151 refVar
->PutObject( pClassModuleObject
);