Calling a macro from another macro

Creating a macro - Writing a Script - Using the API

Calling a macro from another macro

Postby justinbloom » Wed Jan 21, 2009 9:28 am

Somebody PLEASE help

I am using OOo 3.0.0 Base. I am trying to call a macro from another macro in another library. I keep getting an error that says "Basic Runtime Error. Variable not defined." I have spent weeks trying to find out how to make this work and have become extremely frustrated. I can't find any documentation or posts that have helped. Either they show a snippet of code without any context or they are for earlier versions of OOo that don't seem to apply anymore.

I did find a lengthy listing of code that uses executeDispatch() but it didn't make much sense and I figured there has to be a better way. The OOo help says you can execute code a macro by using the fully qualified macro name Library.Module.Macro() but that didn't work either, even after loading the library. Can somebody please help me find out what I need to do to make this work.

Here are the details of my application:

I currently have two forms: PartsEntry and ProjectsEntry. For the PartsEntry form I have a library called partsEntryLib and it has a module called partsEntryHandling. For the ProjectsEntry form I have a library called projectsEntryLib and it has a module called projectsEntryLib. On the ProjectsEntry form I have a button that executes ProjectsEntryLib.ProjectsEntryHandling.EditPart(). I will show the code for this macro below. (It does call an additional macro "startForm()" which loads and shows the PartsEntry form. I don't think it is necessary to show that code.) I will also probably make the code more concise but I have a lot of variables so I can watch what is going on. The macro does fine until the last line where I try to actually execute the other macro.

REM *** EDIT PART ***

sub editPart

dim componentForm as object
dim control as object
dim partsEntryForm as object
dim libraries as object
dim library as object
dim module as object


if isNull(projectsForm) then
init
end if

componentForm = projectsForm.getByName("componentDetails")
control = componentForm.Columns.getByName("partId")
partsEntryForm = startForm("PartsEntry") 'this starts and shows the PartsEntry form
libraries = partsEntryForm.BasicLibraries
library = libraries.getByName("partsEntryLib")
if not libraries.isLibraryLoaded("partsEntryLib") then
libraries.loadLibrary("partsEntryLib")
end if
partsEntryLib.partsEntryHandling.testRun 'this is where it fails
'partsEntryHandling.testRun 'this doesn't work either
'module = library.getByName("PartsHandling") 'this fails, though I can do a hasByName()
'partsEntryForm.ProjectHandling.queryPart(control,3)

end sub


I would really appreciate any help.

Thanks,


Justin
OOo 3.0.X on MS Windows Vista + Windows XP
justinbloom
 
Posts: 3
Joined: Thu Nov 13, 2008 11:40 am

Re: Calling a macro from another macro

Postby B Marcelly » Wed Jan 21, 2009 10:13 pm

Hi,
You can't directly call a macro of a (form) document form a macro in another (form) document.

Note that the method of inserting macros in form documents will be obsolete in OOo 3.1. Because then you will be able to have macros in the Base document (but not in the subordinate document). And then you will be able to call your macro directly.
______
Bernard
B Marcelly
 
Posts: 773
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Calling a macro from another macro

Postby justinbloom » Fri Jan 23, 2009 7:07 am

Does anyone have any idea when 3.1 is supposed to come out, even if its in beta? I am trying to decide if I just want to wait or if I want to move the code to external libraries. I tried to find out a rough date and I couldn't find anything.
OOo 3.0.X on MS Windows Vista + Windows XP
justinbloom
 
Posts: 3
Joined: Thu Nov 13, 2008 11:40 am

Re: Calling a macro from another macro

Postby sqykly » Fri Jan 23, 2009 7:24 am

A disclaimer: I don't use Base or forms, so if anything I say makes no sense in that context, do feel free to laugh, and apologies, etc.

Now then. Have you tried running your macros from events rather than from code? Both dialogs and documents have an event for initialization. If your Project library can open the Part form, then the "On opening document" (or similar) should run from that document with access to its libraries.

If the first form needs to interact with the second afterward, declare a global variable in either library and have the second form set it to its module. If you can still find the module, but not run it, then try setting said global variable to the second form's scriptProvider. Writer documents have individual scriptProvider objects, accessible through e.g. thisComponent.getScriptProvider, though like I disclaimed, I'm not 100% sure whether the same is true of Base forms.

A side note: I've always had quirky and/or sketchy results with using basicLibraries and/or globalScope to get to macros between documents, and you should really never trust Basic's documentation. It tells you to put byVal and byRef in function calls, rather than function declarations. oops!
OOo 3.0.X on Ms Windows XP
sqykly
 
Posts: 27
Joined: Mon Nov 24, 2008 8:28 am

Re: Calling a macro from another macro

Postby B Marcelly » Fri Jan 23, 2009 10:06 am

OpenOffice.org 3.1 release schedule : check regularly http://wiki.services.openoffice.org/wiki/OOoRelease31

Article : Macros in Database Documents explains what will be changed by 3.1

This feature works in the current developer build DEV300m39. Download page. Test at your own risks.

______
Bernard
B Marcelly
 
Posts: 773
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests