[Solved] Call to sub in Standard fails Obj. Var. Not Set

The Application Programming Interface and the OASIS Open Document Format
Post Reply
User avatar
misitu
Posts: 102
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

[Solved] Call to sub in Standard fails Obj. Var. Not Set

Post by misitu »

I would LOVE some help with this!

Something I am failing to see is that the call to a sub in Standard is failing with Object Variable Not Set. I can't figure out which one is not set.

I would have liked to have this working as there are a number of reports, charts, etc., produced for the benefit of end users to get a glance at the accounts without having to know about databases etc.
My aim was to have a generalised save routine which stashes all the recent output in an easy to figure out directory structure. But for some reason, although this has been working, I have now made it not work and it is not clear what is wrong.

I will have to workround at the moment by pasting the code in each report macro but as is well known that does not make for a maintainable system. So any idea of what I am doing wrong will be very welcome.
Object Variable Not Set located at Call (to subroutine in Standard)
Object Variable Not Set located at Call (to subroutine in Standard)

Code: Select all

Sub Main (sysPath as string)
	GlobalScope.BasicLibraries.loadLibrary("Standard")
	select case sysPath
		case "LIVE", "TEST", "UPGRADES"
			rem nothing here
		case else
			print "System Path (" & sysPath & ") Won't Work"
			exit sub
	end select
	basicLibrary = "reports"
	basicModule = "bankStatements"
	systemInstance = sysPath 
	Dim s$ :  s = 	"private:factory/swriter"
	oDoc		=	StarDesktop.loadComponentFromURL(s,"_blank",0,Array())
	dispatcher 	= 	createUnoService("com.sun.star.frame.DispatchHelper")  
	connectToDatabase (systemInstance, "Open Office", "123456")
	SetPageSize
	SetTabStops
	doc=thisComponent
 	cursor=doc.text.createTextCursor
 	cursor.gotoEnd(False)
	PopulateBanner
	printBankAccountStatement
	print systemInstance & " " & basicLibrary & " " & basicModule
rem	call closeAsReadOnly.Main(thisComponent, controller, systemInstance, basicLibrary, basicModule)
rem	v 
call Standard.saveAndClose.Main(doc, systemInstance, basicLibrary, basicModule)	
rem call	Standard.saveAndClose.Main(systemInstance, basicLibrary, basicModule)
rem	saveAndClose
End Sub 
NOTE:
I do have xray installed but have not really got into how it can help diagnosis. Maybe a debug tool of a simpler type is available. I do have MRI installed but it's broken and I will need to reinstall OpenOffice which is a long way down my list of necessaries..
Attachments
saveAndClose.txt
macro saveAndClose which can work under different, possibly unstable, circumstances but cannot call from bankStatements (which DID work previously)
(1.21 KiB) Downloaded 346 times
bankStatements.txt
macro bankStatements which is executed from Dos Batch terminates at call to saveAndClose, but earlier did execute the latter and has now stopped GRRR.
(10.92 KiB) Downloaded 349 times
Last edited by misitu on Wed Mar 01, 2017 4:23 am, edited 1 time in total.
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
JeJe
Volunteer
Posts: 2065
Joined: Wed Mar 09, 2016 2:40 pm

Re: call to sub in Standard fails Object Variable Not Set

Post by JeJe »

Code: Select all

call Standard.saveAndClose.Main(doc, systemInstance, basicLibrary, basicModule)   
rem call   Standard.saveAndClose.Main(systemInstance, basicLibrary, basicModule)
You've got 4 parameters in the first one, 3 in the second

Code: Select all

rem sub saveAndClose (ThisComponent as object, Controller as object, sysInstance as string, basicLibrary as string, basicModule as string)
The macro has 5, none of them optional
Openoffice 4.1.6
Windows 8
User avatar
misitu
Posts: 102
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Call to sub in Standard fails Object Variable Not Set

Post by misitu »

er sorry, but there are a couple of rem's you missed...
the caller has 4 parms and the called has 4: sub Main (ThisComponent as object, sysInstance as string, basicLibrary as string, basicModule as string)

I did try lots of options for the first parm and ThisComponent seems to equate to doc in the caller.

Sorry: I need a lot of rem's, experimenting with whatever might work. In Vain :-(
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
JeJe
Volunteer
Posts: 2065
Joined: Wed Mar 09, 2016 2:40 pm

Re: Call to sub in Standard fails Object Variable Not Set

Post by JeJe »

Try not using ThisComponent as a variable name - try anything else. Don't use reserved words as variable names.
Openoffice 4.1.6
Windows 8
User avatar
misitu
Posts: 102
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Call to sub in Standard fails Object Variable Not Set

Post by misitu »

Thanks VERY MUCH, JeJe.


Right, that helped a bit.
I also changed the call to

Code: Select all

rem call Standard.
saveAndClose.Main(systemInstance, basicLibrary, basicModule)
this got me through to to saveAndClose (in the Standard library)

which failed at

Code: Select all

ThisComponent.storeToURL(storeToUrl, args_ODS())
but that was just the old IOException, URL problem
I changed StoreToURL to StoreAsURL and at least I have completed the output.

THANKS!!!
very much appreciated.

David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
Post Reply