Adding a Nifty Conversion Calculator to

Dmitri Popov

Productivity Sauce

Sep 02, 2008 GMT
Dmitri Popov

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 doesn't have a built-in calculator, you can easily create your own one using 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()





DialogField2.SelectItemPos(0, True)


While Dialog.execute=1



  Select Case DialogField2.SelectedItem

    Case "Fahrenheit -> Celsius"



    Case "Celsius -> Fahrenheit"



    Case "Meter -> Foot" 



    Case "Foot -> Meter"



    End Select


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"



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.


  • openoffice 3.1.0 installation problems

    I have down loaded open office 3.1.0 jre it stays stuck on installation gui. Puppy linux 4.3.1
    Can any one help. I have follwed many faqs, tutorial and instructions. I am not succesful with the installation.
comments powered by Disqus
Subscribe 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.

Learn More