Page 1 of 1

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

Posted: Tue Feb 28, 2017 6:29 pm
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..

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

Posted: Tue Feb 28, 2017 7:45 pm
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

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

Posted: Wed Mar 01, 2017 12:16 am
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 :-(

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

Posted: Wed Mar 01, 2017 1:24 am
by JeJe
Try not using ThisComponent as a variable name - try anything else. Don't use reserved words as variable names.

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

Posted: Wed Mar 01, 2017 4:17 am
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