[Solved] Anomaly between Macro Recorder vs inserted text.

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jrbreton
Posts: 25
Joined: Fri Nov 14, 2008 3:29 am

[Solved] Anomaly between Macro Recorder vs inserted text.

Post by jrbreton »

Welcome beginner. What is your question or comment?
Please try to briefly and clearly tell us: What you want, What you tried, and What happened.
-----------------------------------------------------------------------------------------------------------\
AMDG
A word of understanding explaining the following scenario would be appreciated:

Scenario: OOo3 running under W2000
in Basic IDE I have two macros in the same module. Call them macro1 and macro2. Macro1 was created with the macro recorder. Macro2 is the identical code save for the name. It was created by cutting Macro1 and pasting it into Macro2.

Macro1 runs without problems.
Macro2 will not compile. It stops at a uno call and return :Basic run time error. Object variable not set.. Running the debugger step by step runs to the same call and produces the same error.

Why won't Macro2 run?
Why is the object variable set in Macro1 and not in Macro2?
Last edited by Hagar Delest on Wed Jan 21, 2009 9:34 am, edited 1 time in total.
Reason: tagged [Solved].
OOo 3.0.X on Ms Windows W2k
User avatar
Hagar Delest
Moderator
Posts: 32665
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Anomaly between Macro Recorder vs inserted text.

Post by Hagar Delest »

Can you post the macros?
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
jrbreton
Posts: 25
Joined: Fri Nov 14, 2008 3:29 am

Re: Anomaly between Macro Recorder vs inserted text.

Post by jrbreton »

The content of the IDE is given below. I consits of three subs: Main, countparens and startcount.
startcount = Macro1 above which was created by the Macro recorder. It executes.
countparent = Macro2 above which is a sub which contains the pasted version of startcount. This sub does not execute. When called from Main it debugs ok until the line
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())
is presented to the compiler, ata which point a basic runtime error occurs: Object variable not set.


Sub Main
countparens
End Sub

Sub countparens
rem -----------------------------------------------------------------------
rem define variables with (dim)ension statements
dim document as object
dim dispatcher as object
rem----------------------------------------------------------------------------------
rem get access to document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.Sun.star.Frame.DispatchHelper")
rem----------------------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 0
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 65536
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "hhhh"
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = ""
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 0
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args2())
rem selected commands
rem dispatcher.executeDispatch(document, ".uno:WordRightSel", "" , 0 , array())
rem dispatcher.executeDispatch(document, ".uno:gotoStartofLine","" , 0 , array())
End Sub







sub startcount
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 0
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 65536
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "hhhh"
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = ""
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 0
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Count"
args2(0).Value = 1
args2(1).Name = "Select"
args2(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args2())


end sub
OOo 3.0.X on Ms Windows W2k
FJCC
Moderator
Posts: 9279
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Anomaly between Macro Recorder vs inserted text.

Post by FJCC »

These are your two dispatcher assignments:
countparens
dispatcher = createUnoService("com.Sun.star.Frame.DispatchHelper")

startcount
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

Notice the difference in capitalization of sun/Sun and frame/Frame. I think changing those fixes the problem. A tool like XRay or Mri is very useful for telling you what kind of object you have and therefore where errors might be.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
jrbreton
Posts: 25
Joined: Fri Nov 14, 2008 3:29 am

Re: Anomaly between Macro Recorder vs inserted text.

Post by jrbreton »

AMDG
Thank you. Problem solved! Have downloaded x-ray so I can try it. Marking the problem solved.
OOo 3.0.X on Ms Windows W2k
jrbreton
Posts: 25
Joined: Fri Nov 14, 2008 3:29 am

Re: Anomaly between Macro Recorder vs inserted text.

Post by jrbreton »

Problem solved. Many thanks
OOo 3.0.X on Ms Windows W2k
Post Reply