| View previous topic :: View next topic |
| Author |
Message |
dmonico General User

Joined: 01 Jun 2009 Posts: 5
|
Posted: Mon Jun 01, 2009 3:54 pm Post subject: Word Count for a Particular Field |
|
|
I am curious to know if there is a way to include a word count for a particular field within a Base form. There is an option to do this in File Maker Pro and my organization has recently began to use Open Office to cut costs. This would be very useful for one of our databases, which compiles research for one of our annual publications.
Thank you! |
|
| Back to top |
|
 |
dmonico General User

Joined: 01 Jun 2009 Posts: 5
|
Posted: Wed Jun 10, 2009 12:51 pm Post subject: Still looking for solution |
|
|
| Well I've continued searching online and books as well as speaking with developers. I'm surprised this issue is so hard given it comes standard in other database programs like File Maker. |
|
| Back to top |
|
 |
r4zoli Super User

Joined: 17 May 2005 Posts: 570 Location: Budapest, Hungary
|
Posted: Wed Jun 10, 2009 9:18 pm Post subject: Re: Still looking for solution |
|
|
| dmonico wrote: | | I'm surprised this issue is so hard given it comes standard in other database programs like File Maker. |
I'm not surprised, File maker created in large company with hundreds of developers. OOo Base developed by developers less than ten. |
|
| Back to top |
|
 |
MSPhobe Super User

Joined: 29 Sep 2005 Posts: 529 Location: England
|
Posted: Wed Jun 10, 2009 11:36 pm Post subject: |
|
|
| Post this enquiry at the Macros forum... sounds like just the sort of thing a macro could do (relatively) easily, until it becomes a standard feature of everyone's ooBase. |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8982 Location: Lexinton, Kentucky, USA
|
Posted: Thu Jun 11, 2009 5:35 am Post subject: |
|
|
| Moved to Macros & API. |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Thu Jun 11, 2009 6:16 am Post subject: |
|
|
Not shure if the macro forum is the right place.
If Filemaker's ODBC driver supports this particular function you could use the Filemaker's word count just like [SOLVED] Calculate future date uses the DateAdd from MySQL. Mind that Base is a (primitive) frontend for databases in the first place.
Using the native HSQLDB, we are missing some of the most fundamental functions. There is not even a DateAdd. Before v2.3 we could easily extend the capabilities of HSQL adding some Java-jars to the right place, add the place to OOo's Java options and configure the database to use the additional pack of functions. For some reason I'll never understand, they effectively eliminated this option (they called it "security"). Now you can wrap your Java in a specially crafted add-on which includes the information which database should be allowed to access the new functions. That is not even ridiculous anymore.
As far as macros are concerned, they can only control the frontend part of the database since the connected backend is not part of OpenOffice.org, not even the HSQL engine.
All I can think of is a macro that fetches a particular field's text value on every record change, passes the text to one of the numerous WordCounter functions and display the resulting number in a read-only control. This works for one record at a time. You can not use this in queries against the backend such as SELECT WC("Comments")AS "Word Count". This would require the function to be integrated in the backend or in the source code of the Base frontend.
I don't know about capabilities of the SRB regarding userdefined functions like the ones in Calc. I don't think there is any bridge to macro languages neither. _________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
dmonico General User

Joined: 01 Jun 2009 Posts: 5
|
Posted: Thu Jun 11, 2009 8:44 am Post subject: Thank you... |
|
|
Thank you for your replies and assistance.
Villeroy - Your comment, "All I can think of is a macro that fetches a particular field's text value on every record change, passes the text to one of the numerous WordCounter functions and display the resulting number in a read-only control. This works for one record at a time,"
This is exactly what I'm looking for. I don't need to create any reports based on word count. I just need to know what the word count is in a particular field within each record. Let me know if things bring anything to mind. |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Thu Jun 11, 2009 12:46 pm Post subject: |
|
|
http://www.oooforum.org/forum/search.phtml reveals several hits on "WordCount". There is an example macro in Tools>Macros>Organize>BeanShell... which counts words in the current selection in Writer.
There is a book written by a most valued member of this forum: Database Programming with OpenOffice.org Base & Basic and you may find some dozends of snippets here and elsewhere. Basically, you catch an event thrown by a form (record change) or by a form control (value changed), feed the respective field value to your prefered word-count function and put the return value into another form control, text field, dialog, window title, status bar, whereever you like. _________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
dmonico General User

Joined: 01 Jun 2009 Posts: 5
|
Posted: Fri Jun 12, 2009 1:30 pm Post subject: Coding... |
|
|
Thanks Villroy - I'm new to coding. The extent of my work is getting a modified and created on date field in my database to work properly using the macros.
So, taking the code from the example macro in Open Office, what is it that I should be looking at to change to get it to work for a field within my form in Base?:
| Code: |
//Provides a word count of the selected text in A Writer document.
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XModel;
import com.sun.star.view.XSelectionSupplier;
import com.sun.star.container.XIndexAccess;
import com.sun.star.text.XText;
import com.sun.star.text.XTextRange;
import com.sun.star.script.provider.XScriptContext;
// display the count in a Swing dialog
void doDisplay(numWords) {
wordsLabel = new JLabel("Word count = " + numWords);
closeButton = new JButton("Close");
frame = new JFrame("Word Count");
closeButton.addActionListener(new ActionListener() {
actionPerformed(ActionEvent e) {
frame.setVisible(false);
}
});
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(wordsLabel, BorderLayout.CENTER);
frame.getContentPane().add(closeButton, BorderLayout.SOUTH);
frame.pack();
frame.setSize(190,90);
frame.setLocation(430,430);
frame.setVisible(true);
}
int wordcount() {
result = 0;
// iterate through each of the selections
count = xIndexAccess.getCount();
for(i=0;i<count;i++) {
// get the XTextRange of the selection
xTextRange = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, xIndexAccess.getByIndex(i));
//System.out.println("string: "+xTextRange.getString());
// use the standard J2SE delimiters to tokenize the string
// obtained from the XTextRange
strTok = new StringTokenizer(xTextRange.getString());
result += strTok.countTokens();
}
doDisplay(result);
return result;
}
// The XSCRIPTCONTEXT variable is of type XScriptContext and is available to
// all BeanShell scripts executed by the Script Framework
xModel = (XModel)
UnoRuntime.queryInterface(XModel.class, XSCRIPTCONTEXT.getDocument());
//the writer controller impl supports the css.view.XSelectionSupplier interface
xSelectionSupplier = (XSelectionSupplier)
UnoRuntime.queryInterface(XSelectionSupplier.class, xModel.getCurrentController());
//see section 7.5.1 of developers' guide
// the getSelection provides an XIndexAccess to the one or more selections
xIndexAccess = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class, xSelectionSupplier.getSelection());
count = wordcount();
System.out.println("count = "+count);
return 0;
|
|
|
| Back to top |
|
 |
|