[Solved] Searched string not found

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Mogens@rm.dk
Posts: 2
Joined: Sun Oct 26, 2014 5:19 pm

[Solved] Searched string not found

Post by Mogens@rm.dk »

I am using an subrouting that includes searching a document
I use the following code:

Code: Select all

dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())

dim args2(18) as new com.sun.star.beans.PropertyValue
args2(0).Name = "SearchItem.StyleFamily"
args2(0).Value = 2
args2(1).Name = "SearchItem.CellType"
args2(1).Value = 0
args2(2).Name = "SearchItem.RowDirection"
args2(2).Value = true
args2(3).Name = "SearchItem.AllTables"
args2(3).Value = false
args2(4).Name = "SearchItem.Backward"
args2(4).Value = false
args2(5).Name = "SearchItem.Pattern"
args2(5).Value = false
args2(6).Name = "SearchItem.Content"
args2(6).Value = false
args2(7).Name = "SearchItem.AsianOptions"
args2(7).Value = false
args2(8).Name = "SearchItem.AlgorithmType"
args2(8).Value = 0
args2(9).Name = "SearchItem.SearchFlags"
args2(9).Value = 0
args2(10).Name = "SearchItem.SearchString"
args2(10).Value = "Giv besked, hvis du ikke kan komme"
args2(11).Name = "SearchItem.ReplaceString"
args2(11).Value = ""
args2(12).Name = "SearchItem.Locale"
args2(12).Value = 255
args2(13).Name = "SearchItem.ChangedChars"
args2(13).Value = 2
args2(14).Name = "SearchItem.DeletedChars"
args2(14).Value = 2
args2(15).Name = "SearchItem.InsertedChars"
args2(15).Value = 2
args2(16).Name = "SearchItem.TransliterateFlags"
args2(16).Value = 256
args2(17).Name = "SearchItem.Command"
args2(17).Value = 0
args2(18).Name = "Quiet"
args2(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args2())
The subsequest working of the subroutine depends on whether the search string is found
So I need some kind of response from the search, found or not-found, that I can use in an if ..then .. else statement

Thank you for your help
Last edited by Hagar Delest on Thu Mar 26, 2015 4:18 am, edited 1 time in total.
Reason: tagged [Solved].
Windows XP OpenOffice 3.3
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Searched string not found

Post by floris v »

OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Searched string not found

Post by JohnSUN-Pensioner »

To perform your task, you do not need so much lines of code

Code: Select all

Sub findAndDoSomething
Dim oSDescr As Variant
Dim oResults As Variant
Dim oFound As Variant
Dim sText As String
Dim i As Long
	oSDescr = ThisComponent.createSearchDescriptor()
	oSDescr.setSearchString("Giv besked, hvis du ikke kan komme") ' Or what?
	oResults = ThisComponent.findAll(oSDescr)
	If IsEmpty(oResults) Or IsNull(oResults) Then Exit Sub	' Nothing to do...
	For i = 0 To oResults.getCount()-1	' Enumerate all results
		oFound = oResults.getByIndex(i)	' One of them
' Now do something
' for example sText = oFound.getString()
' or oFound.setString("It was "+(i+1)+" fragment")
' or If oFound.CharHeight <> 10 Then...Else...EndIf
	Next i
End Sub
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
Mogens@rm.dk
Posts: 2
Joined: Sun Oct 26, 2014 5:19 pm

Re: Searched string not found

Post by Mogens@rm.dk »

Hi John
Thank you very much for your reply
That is just what I asked for.
Hope you find a job soon!!

Mogens
Windows XP OpenOffice 3.3
ccirtina
Posts: 17
Joined: Sat Oct 01, 2011 8:09 pm

Re: [Solved] Searched string not found

Post by ccirtina »

the code works well, but can we extend to search a group of words?
OpenOffice 4.1.3 on Windows10
Post Reply