OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

findNext in Calc only delivers first match, nothing more

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
seppdepp
Newbie
Newbie


Joined: 13 Sep 2010
Posts: 1

PostPosted: Mon Sep 13, 2010 11:35 am    Post subject: findNext in Calc only delivers first match, nothing more Reply with quote

Hello,
this is my first macro in OO basic. I have a spreadsheet with several tables. Each table represents one month.
On this tables there are listings, from 1-31 for each day, and in some lines there is a cell called "RK", if there were such spendings during that day.
I want to get all values of the cells next to this "RK" cells of all tables in my current table.

Example of one of the to be searched tables:
Code:
day | subject | Roomcost | value
---------------------------------------
4   | Vers    |          | 5,--
6   | Vers    |          | 1,--
7   | Bill    | RK       | 16,18
8   | www     |          | 1,--
11  | www     |          | 2,--
15  | Current | RK       | 95,--
15  | Water   | RK       | 17,--


I think I know how to do this, but the problem is that findFirst delivers me the first result/match but findNext is always NULL, therefore I will only get the very first match.

My current code will deliver the first match which is 7 | Bill | RK| 16,18, and nothing else, instead, just continues to the next table.

So what is wrong here?

Code:
Sub Main
Dim oDocument as Object
Dim oSheets as object, rkSheet As Object
Dim SearchDesc As Object
Dim x As Integer, y As Integer ' Will be used to do the output coordinates

oDocument = ThisComponent
oSheets = oDocument.Sheets      'Get all sheets
y = 5
x = 8
rkSheet   = oSheets.getByName("Roomcost")

For c = 0 to oSheets.Count - 1

ThisSheet = oSheets.getByIndex(c)

' Print each month's name
rkSheet.getCellByPosition(x, y).String = ThisSheet.getname()
rkSheet.getCellByPosition(x, y).CharWeight = com.sun.star.awt.FontWeight.BOLD
y = y + 1

SearchDesc = ThisSheet.createSearchDescriptor()
SearchDesc.SearchCaseSensitive = true
SearchDesc.SearchWords = true
SearchDesc.searchString="RK"

Found = ThisSheet.findFirst (SearchDesc)

Do Until IsNull(Found)

  rkSheet.getCellByPosition(x, y).String   =  Found.string 'Test output 
  y = y + 1 
 
  Found = ThisSheet.findNext(Found.End, SearchDesc)
 
Loop
Next

End Sub


Thank you everybody.
_________________
OpenOffice 3.2.1 Mac
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Mon Sep 13, 2010 4:02 pm    Post subject: Reply with quote

Found.End does not work in a spreadsheet. Try the following for your Do loop.
Code:
Do Until IsNull(Found)
 Print Found.string
 Value = ThisSheet.GetCellByPosition(Found.CellAddress.Column+1,Found.CellAddress.Row)
 Print Value.value 'If text then Value.String.
 Found = ThisSheet.findNext(Found, SearchDesc)
Loop
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group