Patrick Draper,
Please download AndrewMacro.odt. Read the section titled "Searching a
Calc document". I think that you will find it useful.
Patrick Draper wrote:
Hi, I want to use match or hlookup inside an open office basic macro,
and I am having a lot of trouble with it.
I've written an equivalent function that does not use match, but this
is very slow.
I've googled for days on this, and I can't tell if I'm completely
offbase on what I want to do. Is it legal to use a match formula in a
basic script?
Here's an idea of the code I want to write:
sheet2_column=sheet2.match(heading,"A1:IV1",0)
Unfortunately, that is not valid. You may be able to directly call the
match method. Hmm. You might be able to use the
"com.sun.star.sheet.FunctionAccess" service.
This is the code that I have to do the same rough thing:
function search_row_for_text (rw, txt)
blank_count = 0
search_row_for_text=-1
' read each header of sheet2 until one matches the string passed in
for i = 0 to 255
tmptxt = Sheet2.getcellbyposition (i,0).string()
if tmptxt = txt then
search_row_for_text=i
i=255
endif
next
end functio
This is too inefficient. You obtain each cell individually. To reiterate
what you will read in my document.
- Each cell individually is very slow.
- Obtain all of the cells into a single array and iterating that is much
faster.
- Use the built-in search capabilities is the fastest solution.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]