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
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
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.