In this tutorial we will be creating a simple currency converter that will convert U.S. dollars to Euro. This is a fun little project that can be useful on a web site or on your computer if you ever need it. This will be your personal converter, so even though I will show you how to make one it is up to you to be creative and put your spin on the converter. Remember that this is a basic USD to Euro converter and will only have this option, feel free to add more conversions at the conclusion of this tutorial.

Setting Up

If you have not done so, set up a windows form application. Open visual studio and click File > New > Project. In the ‘Installed Templates’ column, expand Other Languages > Visual Basic and click on Windows. Next select Windows Forms Application, name the file Currency Converter and click OK. You should see a form similar to the screenshot below:

Currency Converter 1

Step One

We will design the converter before we do any coding. Click on the form and look at its ‘Properties’ window. Change the text string to Currency Converter as this will be the name of the form design. Now let’s add two label items to distinguish USD and EUR currency. Expand the ‘Toolbox’ panel and place two labels on the form. Change the text of both text fields in the properties window to USD and EUR. Also make sure to open the ‘Font’ category in the properties window and change the ‘Bold’ value to True for both labels. Change the name of USD to lblUsd and the name of EUR to lblEur.

Now we need to add text boxes next to each label to display the amount of money being converted. Expand the ‘Toolbox’ panel and place a TextBox item next to each label, having a total of two text boxes on the form. Click on the text box associated with ‘EUR’ and look in the properties window. Change the ‘ReadOnly’ value to True and change its ‘BackColor’ to the custom color Gray. Change the name of the text box for USD to txtUsd and the name of EUR to xtEur.

Grab and place another Label item from the ‘Toolbox’ panel next to the USD text box. This will be used as an error message when a wrong data type is put in. Change it’s ‘Text’ to an asterisk (*) and its ‘ForeColor’ to Red. Change it’s ‘Visible’ property to False since we only want it to appear when wrong data is put in. Also make sure to change its name to lblError.

Expand the ‘Toolbox’ panel to select and place a Button item on the form. This button will be used as the convert button, acting like an equals button on a calculator, so place it accordingly on the form. Change the text of the button to Convert from the button properties window and change the name to btnConvert.

Currency Converter 1

When done, your form should look similar to the one show above, though the design pattern may be different.

Step Two

Now that we have the design of the converter done, we can start on the code that does the conversion behind the scenes. Double click on the Convert button to open the ‘Default.aspx.vb’ class. We will use an ‘If’ statement to determine if the text inputted by the user is numerical, non numerical or just empty and will display a red asterisk to signal the user to enter a number if it is anything but numerical. Apply the code in the code snippet below to your Form1.vb class:

Make sure to have the names of each item in the form the same as the was described earlier. It is important because if a name is different, the code in the snippet will not work.

Output

Run the page by either clicking the green arrow at the top or pressing F5. Type in a number and you will see the currency conversion in the EUR text box.

Currency Converter 2

Conversion of 1 USD to EUR.

Currency Converter 3

The red asterisk appeared because the input was of the wrong data type.

This is a neat application that can be used for trading, fun and more. Add more conversions to it now that you know how to make it and add your own spin to it, get creative and have fun.

Download Source Files