Adding a Nifty Conversion Calculator to OpenOffice.org
Productivity Sauce
A conversion calculator can save you a lot of time and unnecessary mouse clicks when you need to convert values in a document from the imperial to the metric system (or vice versa). Although OpenOffice.org doesn't have a built-in calculator, you can easily create your own one using OpenOffice.org Basic. Start with creating a dialog with three fields in it:
- NumericField1 -- a numeric field where the user enters the value to be converted
- ListBox1 -- a drop-down list containing a list of the available conversion options (e.g., Fahrenheit -> Celsius, Foot -> Meter, and so on)
- NumericField2 -- a numeric field which displays the converted value
The dialog box should also have two buttons: Convert (type OK) which performs the conversion and Cancel (type Cancel) which closes the dialog. Save the dialog and give it the name ConvertSystemDialog.
With the dialog in place, you start working on the code. The macro itself is pretty simple. It starts with initializing and displaying the ConvertSystemDialog dialog. It then creates a loop which runs the macro until the user presses the Cancel button. In the loop, there is the Select Case statement which chooses the appropriate Case code block based on the option the user selects from the ListBox1 drop-down list. For example, if the user selects the Fahrenheit -> Celsius item, the macro runs the Case "Fahrenheit -> Celsius" code block.
Sub QuickConverter()
OpenDialog("ConvertSystemDialog")
Dialog=CreateUnoDialog(TheDialog)
DialogField1=Dialog.getControl("NumericField1")
DialogField2=Dialog.getControl("ListBox1")
DialogField2.SelectItemPos(0, True)
DialogField3=Dialog.getControl("NumericField2")
While Dialog.execute=1
DialogField1=Dialog.getControl("NumericField1")
InputValue=DialogField1.value
Select Case DialogField2.SelectedItem
Case "Fahrenheit -> Celsius"
ConvertedValue=(InputValue-32)*5/9
DialogField3=Dialog.getControl("NumericField2").setValue(ConvertedValue)
Case "Celsius -> Fahrenheit"
ConvertedValue=InputValue*9/5+32
DialogField3=Dialog.getControl("NumericField2").setValue(ConvertedValue)
Case "Meter -> Foot"
ConvertedValue=InputValue*3.28
DialogField3=Dialog.getControl("NumericField2").setValue(ConvertedValue)
Case "Foot -> Meter"
ConvertedValue=InputValue/3.28
DialogField3=Dialog.getControl("NumericField2").setValue(ConvertedValue)
End Select
WEnd
End Sub The macro above converts temperature and distance values, but you can easily modify it to include other types of conversion. For example, if you want the calculator to include the gallon to liter conversion, add the appropriate option to the ListBox1 field and create a new Case block containing the conversion formula:
Case "Gallon -> Liter"
ConvertedValue=InputValue*3.78
DialogField3=Dialog.getControl("NumericField2").setValue(ConvertedValue) Now you can quickly perform conversions from the convenience of your favorite productivity suite. If you don't fancy creating the described conversion calculator from scratch, you can get it as part of the Writer's Tools extension.
Comments
comments powered by DisqusSubscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Keep Android Open
Google has announced that, soon, anyone looking to develop Android apps will have to first register centrally with Google.
-
Kernel 7.0 Now in Testing
Linus Torvalds has announced the first Release Candidate (RC) for the 7.x kernel is available for those who want to test it.
-
Introducing matrixOS, an Immutable Gentoo-Based Linux Distro
It was only a matter of time before a developer decided one of the most challenging Linux distributions needed to be immutable.
-
Chaos Comes to KDE in KaOS
KaOS devs are making a major change to the distribution, and it all comes down to one system.
-
New Linux Botnet Discovered
The SSHStalker botnet uses IRC C2 to control systems via legacy Linux kernel exploits.
-
The Next Linux Kernel Turns 7.0
Linus Torvalds has announced that after Linux kernel 6.19, we'll finally reach the 7.0 iteration stage.
-
Linux From Scratch Drops SysVinit Support
LFS will no longer support SysVinit.
-
LibreOffice 26.2 Now Available
With new features, improvements, and bug fixes, LibreOffice 26.2 delivers a modern, polished office suite without compromise.
-
Linux Kernel Project Releases Project Continuity Document
What happens to Linux when there's no Linus? It's a question many of us have asked over the years, and it seems it's also on the minds of the Linux kernel project.
-
Mecha Systems Introduces Linux Handheld
Mecha Systems has revealed its Mecha Comet, a new handheld computer powered by – you guessed it – Linux.

openoffice 3.1.0 installation problems
Can any one help. I have follwed many faqs, tutorial and instructions. I am not succesful with the installation.