diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/classes/sbxmod.cxx basic/source/classes/sbxmod.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/classes/sbxmod.cxx	2007-10-26 13:21:30.000000000 +0100
+++ basic/source/classes/sbxmod.cxx	2007-10-26 13:40:30.000000000 +0100
@@ -1978,10 +1978,17 @@ SbxArray* SbMethod::GetLocals()
 		return NULL;
 }
 
+void SbMethod::ClearStatics()
+{
+	refStatics = NULL;
+	
+}
 SbxArray* SbMethod::GetStatics()
 {
-	DBG_ERROR( "SbMethod::GetStatics() invalid, AB fragen" )
-	return NULL;
+	
+	if ( !refStatics.Is() )
+		refStatics = new SbxArray;
+	return refStatics;
 }
 
 BOOL SbMethod::LoadData( SvStream& rStrm, USHORT nVer )
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/dim.cxx basic/source/comp/dim.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/dim.cxx	2007-10-26 13:21:28.000000000 +0100
+++ basic/source/comp/dim.cxx	2007-10-26 13:40:30.000000000 +0100
@@ -53,7 +53,7 @@ SbiSymDef* SbiParser::VarDecl( SbiDimLis
 	if( Peek() == LPAREN )
 		pDim = new SbiDimList( this );
 	pDef->SetType( t );
-	if( bStatic )
+	if( bVBASupportOn && bStatic )
 		pDef->SetStatic();
 	TypeDecl( *pDef );
 	if( !ppDim && pDim )
@@ -186,7 +186,10 @@ void SbiParser::TypeDecl( SbiSymDef& rDe
 
 void SbiParser::Dim()
 {
-	DefVar( _DIM, FALSE );
+	if ( pProc )
+		DefVar( _DIM, pProc->IsStatic() );
+	else
+		DefVar( _DIM, FALSE );
 }
 
 void SbiParser::DefVar( SbiOpcode eOp, BOOL bStatic )
@@ -272,7 +275,7 @@ void SbiParser::DefVar( SbiOpcode eOp, B
 
 	// AB 9.7.97, #40689, Statics -> Modul-Initialisierung, in Sub ueberspringen
 	UINT32 nEndOfStaticLbl = 0;
-	if( bStatic )
+	if( !bVBASupportOn && bStatic )
 	{
 		nEndOfStaticLbl = aGen.Gen( _JUMP, 0 );
 		aGen.Statement();	// bei static hier nachholen
@@ -340,13 +343,11 @@ void SbiParser::DefVar( SbiOpcode eOp, B
                                 goto global;
 				case SbPUBLIC:	eOp2 = bPersistantGlobal ? _PUBLIC_P : _PUBLIC;
 								// AB 9.7.97, #40689, kein eigener Opcode mehr
-								/*
-								if( bStatic )
+								if( bVBASupportOn && bStatic )
 								{
 									eOp2 = _STATIC;
 									break;
 								}
-								*/
 				global:			aGen.BackChain( nGblChain );
 								nGblChain = 0;
 								bGblDefs = bNewGblDefs = TRUE;
@@ -477,14 +478,14 @@ void SbiParser::DefVar( SbiOpcode eOp, B
 		// d.h. pPool muss immer am Schleifen-Ende zurueckgesetzt werden.
 		// auch bei break
 		pPool = pOldPool;
-		continue;		// MyBreak überspingen
+		continue;		// MyBreak uberspingen
 	MyBreak:
 		pPool = pOldPool;
 		break;
 	}
 
 	// AB 9.7.97, #40689, Sprung ueber Statics-Deklaration abschliessen
-	if( bStatic )
+	if( !bVBASupportOn && bStatic )
 	{
 		// globalen Chain pflegen
 		nGblChain = aGen.Gen( _JUMP, 0 );
@@ -501,7 +502,10 @@ void SbiParser::DefVar( SbiOpcode eOp, B
 
 void SbiParser::ReDim()
 {
-	DefVar( _REDIM, FALSE );
+	if ( pProc )
+		DefVar( _REDIM, pProc->IsStatic() );
+	else
+		DefVar( _REDIM, FALSE );
 }
 
 // ERASE array, ...
@@ -1023,11 +1027,13 @@ void SbiParser::DefProc( BOOL bStatic, B
 		// Normalfall: Lokale Variable->Parameter->Globale Variable
 		pProc->GetLocals().SetParent( &pProc->GetParams() );
 		pPool = &pProc->GetLocals();
+		pProc->SetStatic( FALSE );
 	}
+	else if ( bVBASupportOn )
+		pProc->SetStatic( TRUE );
 	else
-	{
 		Error( SbERR_NOT_IMPLEMENTED ); // STATIC SUB ...
-	}
+
 
 	pProc->Define();
 	OpenBlock( eExit );
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/exprgen.cxx basic/source/comp/exprgen.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/exprgen.cxx	2006-10-12 15:26:47.000000000 +0100
+++ basic/source/comp/exprgen.cxx	2007-10-26 13:40:30.000000000 +0100
@@ -132,9 +132,17 @@ void SbiExprNode::Gen( RecursiveMode eRe
                     (aVar.pDef->IsGlobal() ? _FIND_G : _FIND);
 		}
 
-		if( eOp == _FIND && pGen->GetParser()->bClassModule )
-			eOp = _FIND_CM;
-
+		if( eOp == _FIND )
+		{
+	
+			SbiProcDef* pProc = aVar.pDef->GetProcDef();
+			if ( pGen->GetParser()->bClassModule )
+				eOp = _FIND_CM;
+			else if ( aVar.pDef->IsStatic() || pProc && pProc->IsStatic() )
+			{
+				eOp = _FIND_STATIC;
+			}
+		}
 		for( SbiExprNode* p = this; p; p = p->aVar.pNext )
 		{
 			if( p == this && pWithParent_ != NULL )
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/exprtree.cxx basic/source/comp/exprtree.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/exprtree.cxx	2007-10-26 13:21:29.000000000 +0100
+++ basic/source/comp/exprtree.cxx	2007-10-26 13:40:30.000000000 +0100
@@ -286,6 +286,11 @@ SbiExprNode* SbiExpression::Term()
 		if( bObj )
 			eType = SbxOBJECT;
 		pDef = AddSym( eTok, *pParser->pPool, eCurExpr, aSym, eType, pPar );
+		// Looks like this is a local ( but undefined variable )
+		// if it is in a static procedure then make this Symbol
+		// static
+		if ( !bObj && pParser->pProc && pParser->pProc->IsStatic() )
+		    pDef->SetStatic();
 	}
 	else
 	{
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/sbcomp.cxx basic/source/comp/sbcomp.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/sbcomp.cxx	2007-10-26 13:19:45.000000000 +0100
+++ basic/source/comp/sbcomp.cxx	2007-10-26 13:40:30.000000000 +0100
@@ -142,6 +142,13 @@ BOOL SbModule::Compile()
 	if( bRet )
 	{
 		pBasic->ClearAllModuleVars();
+		// clear all method statics
+		for( USHORT i = 0; i < pMethods->Count(); i++ )
+		{
+			SbMethod* p = PTR_CAST(SbMethod,pMethods->Get( i ) );
+			if( p )
+				p->ClearStatics();
+		}
 
 		// #i31510 Init other libs only if Basic isn't running
 		if( pINST == NULL )
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/symtbl.cxx basic/source/comp/symtbl.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/comp/symtbl.cxx	2006-11-03 15:10:55.000000000 +0000
+++ basic/source/comp/symtbl.cxx	2007-10-26 13:40:30.000000000 +0100
@@ -428,6 +428,7 @@ SbiProcDef::SbiProcDef( SbiParser* pPars
 	mePropMode = PROPERTY_MODE_NONE;
 	bPublic = TRUE;
 	bCdecl	= FALSE;
+	bStatic = FALSE;
 	// Fuer Returnwerte ist das erste Element der Parameterliste
 	// immer mit dem Namen und dem Typ der Proc definiert
 	aParams.AddSym( aName );
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/inc/opcodes.hxx basic/source/inc/opcodes.hxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/inc/opcodes.hxx	2007-10-26 13:21:14.000000000 +0100
+++ basic/source/inc/opcodes.hxx	2007-10-26 13:40:30.000000000 +0100
@@ -167,6 +167,8 @@ enum SbiOpcode {
     _DCREATE_REDIMP,	// Objekt-Array redimensionieren (+StringId+StringID)
 	_FIND_CM,        	// Search inside a class module (CM) to enable global search in time
 	_PUBLIC_P, 			//  Module global Variable (persisted between calls)(+StringID+Typ)
+	_FIND_STATIC,        	//  local static var lookup (+StringID+Typ) 
+
 	SbOP2_END
 
 };
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/inc/runtime.hxx basic/source/inc/runtime.hxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/inc/runtime.hxx	2007-10-26 13:21:14.000000000 +0100
+++ basic/source/inc/runtime.hxx	2007-10-26 15:21:29.000000000 +0100
@@ -331,6 +331,7 @@ class SbiRuntime
 	SbiInstance*   pInst;			// aktiver Thread
 	SbModule*	  pMod;				// aktuelles Modul
 	SbMethod* 	  pMeth;			// Methoden-Instanz
+	SbMethod* 	  pRealMeth;
 	SbiIoSystem*   pIosys;			// I/O-System
 	const SbiImage* pImg;           // Code-Image
 	SbxArrayRef   refExprStk;       // expression stack
@@ -392,7 +393,7 @@ class SbiRuntime
 	}
 
 	SbxVariable* FindElement
-	( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError, BOOL );
+	( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError, BOOL bLocal, BOOL bStatic = FALSE );
 	void SetupArgs( SbxVariable*, UINT32 );
 	SbxVariable* CheckArray( SbxVariable* );
 
@@ -464,16 +465,19 @@ class SbiRuntime
 	// Alle Opcodes mit zwei Operanden
 	void StepRTL( UINT32, UINT32 ),		StepPUBLIC( UINT32, UINT32 ),	StepPUBLIC_P( UINT32, UINT32 );		
 	void StepPUBLIC_Impl( UINT32, UINT32, bool bUsedForClassModule );
+	void StepFIND_Impl( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError, BOOL bLocal, BOOL bStatic = FALSE );
 	void StepFIND( UINT32, UINT32 ),    StepELEM( UINT32, UINT32 );
 	void StepGLOBAL( UINT32, UINT32 ),  StepLOCAL( UINT32, UINT32 );
 	void StepPARAM( UINT32, UINT32), 	StepCREATE( UINT32, UINT32 );
 	void StepCALL( UINT32, UINT32 ),    StepCALLC( UINT32, UINT32 );
 	void StepCASEIS( UINT32, UINT32 ),  StepSTMNT( UINT32, UINT32 );
+	SbxVariable* StepSTATIC_Impl( String& aName, SbxDataType& t );
 	void StepOPEN( UINT32, UINT32 ),	StepSTATIC( UINT32, UINT32 );
 	void StepTCREATE(UINT32,UINT32),	StepDCREATE(UINT32,UINT32);
 	void StepGLOBAL_P( UINT32, UINT32 ),StepFIND_G( UINT32, UINT32 );
 	void StepDCREATE_REDIMP(UINT32,UINT32), StepDCREATE_IMPL(UINT32,UINT32);
 	void StepFIND_CM( UINT32, UINT32 );
+	void StepFIND_STATIC( UINT32, UINT32 );
 public:
 	void          SetVBAEnabled( bool bEnabled ) { bVBAEnabled = bEnabled; };            
 	USHORT		GetImageFlag( USHORT n ) const;
Only in basic/source/inc: .runtime.hxx.swp
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/inc/symtbl.hxx basic/source/inc/symtbl.hxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/inc/symtbl.hxx	2007-10-26 13:19:45.000000000 +0100
+++ basic/source/inc/symtbl.hxx	2007-10-26 13:40:30.000000000 +0100
@@ -207,6 +207,7 @@ class SbiProcDef : public SbiSymDef {	//
 	BOOL   bCdecl  : 1;				// TRUE: CDECL angegeben
 	BOOL   bPublic : 1;				// TRUE: proc ist PUBLIC
 	BOOL   mbProcDecl : 1;			// TRUE: instanciated by SbiParser::ProcDecl
+	BOOL   bStatic : 1;				// TRUE:
 public:
 	SbiProcDef( SbiParser*, const String&, BOOL bProcDecl=false );
 	virtual ~SbiProcDef();
@@ -219,6 +220,8 @@ public:
 	String& GetAlias() 		  		{ return aAlias;   }
 	void SetPublic( BOOL b )		{ bPublic = b;	   }
 	BOOL IsPublic() const			{ return bPublic;  }
+	void SetStatic( BOOL b )		{ bStatic = b;	   }
+	BOOL IsStatic() const			{ return bStatic;  }
 	void SetCdecl( BOOL b = TRUE) 	{ bCdecl = b;      }
 	BOOL IsCdecl() const			{ return bCdecl;   }
 	BOOL IsUsedForProcDecl() const	{ return mbProcDecl; }
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/runtime/runtime.cxx basic/source/runtime/runtime.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/runtime/runtime.cxx	2007-10-26 13:21:30.000000000 +0100
+++ basic/source/runtime/runtime.cxx	2007-10-26 13:40:30.000000000 +0100
@@ -213,6 +213,7 @@ SbiRuntime::pStep2 SbiRuntime::aStep2[] 
 	&SbiRuntime::StepDCREATE_REDIMP, // Objekt-Array redimensionieren (+StringID+StringID)
 	&SbiRuntime::StepFIND_CM,    // Search inside a class module (CM) to enable global search in time
 	&SbiRuntime::StepPUBLIC_P,    // Search inside a class module (CM) to enable global search in time
+	&SbiRuntime::StepFIND_STATIC,    // Search inside a class module (CM) to enable global search in time
 };
 
 
@@ -508,7 +509,7 @@ SbxArray* SbiInstance::GetLocals( SbMeth
 
 SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, UINT32 nStart )
 		 : rBasic( *(StarBASIC*)pm->pParent ), pInst( pINST ), 
-		   pMod( pm ), pMeth( pe ), pImg( pMod->pImage ), m_nLastTime(0)
+		   pMod( pm ), pMeth( pe ), pRealMeth(0), pImg( pMod->pImage ), m_nLastTime(0)
 {
 	nFlags	  = pe ? pe->GetDebugFlags() : 0;
 	pIosys	  = pInst->pIosys;
@@ -544,6 +545,13 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
 	pRefSaveList = NULL;
 	pItemStoreList = NULL;
 	bVBAEnabled = isVBAEnabled();
+	if ( pMeth )
+	{
+		SbxVariable* p = pMod->Find( pMeth->GetName(), SbxCLASS_METHOD  );
+		SbMethod* pMethod= p ? PTR_CAST(SbMethod,p) : NULL;
+		if ( pMethod )
+			pRealMeth = pMethod;
+	}
 }
 
 SbiRuntime::~SbiRuntime()
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/runtime/step2.cxx basic/source/runtime/step2.cxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/source/runtime/step2.cxx	2007-10-26 13:21:14.000000000 +0100
+++ basic/source/runtime/step2.cxx	2007-10-26 15:24:03.000000000 +0100
@@ -117,7 +117,7 @@ SbxVariable* VBAFind( const String& rNam
 // 0x8000 - Argv ist belegt
 
 SbxVariable* SbiRuntime::FindElement
-	( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError nNotFound, BOOL bLocal )
+	( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError nNotFound, BOOL bLocal, BOOL bStatic )
 {
 	SbxVariable* pElem = NULL;
 	if( !pObj )
@@ -153,9 +153,17 @@ SbxVariable* SbiRuntime::FindElement
 			nOp1 = nOp1 | 0x8000; // indicate params are present
 			aName = String::CreateFromAscii("Evaluate");
 		}
-
 		if( bLocal )
-			pElem = refLocals->Find( aName, SbxCLASS_DONTCARE );
+		{
+			if ( bStatic )
+			{	
+				if ( pRealMeth )
+					pElem = pRealMeth->GetStatics()->Find( aName, SbxCLASS_DONTCARE );
+			}
+
+			if ( !pElem )
+				pElem = refLocals->Find( aName, SbxCLASS_DONTCARE );
+		}
 		if( !pElem )
 		{
 			// Die RTL brauchen wir nicht mehr zu durchsuchen!
@@ -255,12 +268,17 @@ SbxVariable* SbiRuntime::FindElement
 				}
 				else
 				{
-					// Sonst Variable neu anlegen
-					pElem = new SbxVariable( t );
-					if( t != SbxVARIANT )
-						pElem->SetFlag( SBX_FIXED );
-					pElem->SetName( aName );
-					refLocals->Put( pElem, refLocals->Count() );
+					if ( bStatic )
+						pElem = StepSTATIC_Impl( aName, t );
+					if ( !pElem )
+					{
+						// Sonst Variable neu anlegen
+						pElem = new SbxVariable( t );
+						if( t != SbxVARIANT )
+							pElem->SetFlag( SBX_FIXED );
+						pElem->SetName( aName );
+						refLocals->Put( pElem, refLocals->Count() );
+					}
 				}
 			}
 		}
@@ -645,29 +663,39 @@ void SbiRuntime::StepRTL( UINT32 nOp1, U
 	PushVar( FindElement( rBasic.pRtl, nOp1, nOp2, SbERR_PROC_UNDEFINED, FALSE ) );
 }
 
+void
+SbiRuntime::StepFIND_Impl( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError nNotFound, BOOL bLocal, BOOL bStatic )
+{
+	if( !refLocals )
+		refLocals = new SbxArray;
+	PushVar( FindElement( pObj, nOp1, nOp2, nNotFound, bLocal, bStatic ) );
+}
 // Laden einer lokalen/globalen Variablen (+StringID+Typ)
 
 void SbiRuntime::StepFIND( UINT32 nOp1, UINT32 nOp2 )
 {
-	if( !refLocals )
-		refLocals = new SbxArray;
-	PushVar( FindElement( pMod, nOp1, nOp2, SbERR_PROC_UNDEFINED, TRUE ) );
+	StepFIND_Impl( pMod, nOp1, nOp2, SbERR_PROC_UNDEFINED, TRUE );
 }
 
 // Search inside a class module (CM) to enable global search in time
 void SbiRuntime::StepFIND_CM( UINT32 nOp1, UINT32 nOp2 )
 {
-	if( !refLocals )
-		refLocals = new SbxArray;
 
 	SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pMod);
 	if( pClassModuleObject )
 		pMod->SetFlag( SBX_GBLSEARCH );
-	PushVar( FindElement( pMod, nOp1, nOp2, SbERR_PROC_UNDEFINED, TRUE ) );
+
+	StepFIND_Impl( pMod, nOp1, nOp2, SbERR_PROC_UNDEFINED, TRUE );
+
 	if( pClassModuleObject )
 		pMod->ResetFlag( SBX_GBLSEARCH );
 }
 
+void SbiRuntime::StepFIND_STATIC( UINT32 nOp1, UINT32 nOp2 )
+{
+	StepFIND_Impl( pMod, nOp1, nOp2, SbERR_PROC_UNDEFINED, TRUE, TRUE );
+}
+
 // Laden eines Objekt-Elements (+StringID+Typ)
 // Das Objekt liegt auf TOS
 
@@ -1217,19 +1245,27 @@ void SbiRuntime::StepFIND_G( UINT32 nOp1
 }
 
 
+SbxVariable* SbiRuntime::StepSTATIC_Impl( String& aName, SbxDataType& t )
+{
+    SbxVariable* p = NULL;
+    if ( pRealMeth )
+    {
+        SbxArray* pStatics = pRealMeth->GetStatics();
+        if( pStatics && ( pStatics->Find( aName, SbxCLASS_DONTCARE ) == NULL ) )
+        {
+            p = new SbxVariable( t );
+            if( t != SbxVARIANT )
+                p->SetFlag( SBX_FIXED );
+            p->SetName( aName );
+            pStatics->Put( p, pStatics->Count() );
+        }
+    }
+    return p;
+}
 // Einrichten einer statischen Variablen (+StringID+Typ)
-
 void SbiRuntime::StepSTATIC( UINT32 nOp1, UINT32 nOp2 )
 {
-    (void)nOp1;
-    (void)nOp2;
-	/* AB #40689, wird nicht mehr verwendet
-	String aName( pImg->GetString( nOp1 ) );
-	SbxDataType t = (SbxDataType) nOp2;
-	SbxVariable* p = new SbxVariable( t );
-	p->SetName( aName );
-	pInst -> GetStatics()->Put( p, pInst->GetStatics()->Count() );
-	*/
-}
-
-
+    String aName( pImg->GetString( nOp1 ) );
+    SbxDataType t = (SbxDataType) nOp2;
+    StepSTATIC_Impl( aName, t );
+}
diff -rup /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/inc/basic/sbmeth.hxx basic/inc/basic/sbmeth.hxx
--- /data4/sles/build-source-only/ooo-build/build/oog680-m5/basic/inc/basic/sbmeth.hxx	2007-10-26 13:19:45.000000000 +0100
+++ basic/inc/basic/sbmeth.hxx	2007-10-26 13:40:30.000000000 +0100
@@ -58,7 +58,7 @@ class SbMethod : public SbxMethod
 	friend class SbIfaceMapperMethod;
 
 	SbMethodImpl* mpSbMethodImpl;			// Impl data
-
+	SbxArrayRef refStatics;
 	SbModule* pMod;
 	USHORT    nDebugFlags;
 	USHORT	  nLine1, nLine2;
@@ -76,6 +76,7 @@ public:
 	virtual SbxInfo* GetInfo();
 	SbxArray* GetLocals();
 	SbxArray* GetStatics();
+	void      ClearStatics();
 	SbModule* GetModule() 				 { return pMod; 	   }
 	UINT32	  GetId() const				 { return nStart;	   }
 	USHORT    GetDebugFlags()			 { return nDebugFlags; }
