Currency Converter
Currency Converter
Welcome to the currency converter tutorial in visual basic. In this tutorial we will be using Visual studio 2010
(you can get for free or even the 2015 version) with visual basic programming language. This will be the second
currency converter we create in visual basic. The last one we made used Radio buttons to change the currency
rates. In this one we will be making one which you can dictate the currency rates and then make sure it does the
maths accurately.
Enter Country
No
Enter
Conversion
Click
Enter Amount
calculate
Yes
Algorithm
Pointer RichTetBox
vdLEIIIErLKet
Button TetBox
A Label
A LinkLabel CheckBox ToolTip
Fom
Label1
Label2
Label3
Autonl
Label4
HAs you can we have our 4 labels, 3 text boxes and 1 button for the
interface of this application.
Lets start changing the texts of the labels on screen. Click on label1 and look into the properties window. You
will find an option called text. Inside that we can add any text which will change Label1.
Properties
Labell System.Windows.Foms.La
Location 68,43
Locked False
Forml
Margin 3,0, 3, 0
MaximumSize 0, 0
DMinimumSize 0, 0
Modifiers Friend TCourtry
Padding 0,0,0,0
RightToleft No
Labe2
D Size 39, 13
Tablndex 4
Labe3
Tag
Text Country
TetAlign TopLeft
UseCompatib False
UseMnemoni True Buton1
UseWaitCursc False
Visible True
Label4
Text
The tet associated with the control.
Forml1
Country
Conversion Rate
Amount
Button 1
Total:
Here is the final view of what the program should look like now with the text changed. You can change the
button text as well. Let's give it a text of calculate in it since it will calculate the conversion rate for us.
Calculate
Now run the GUl to see if everything is in order. There are few ways to run an app in visual studio.
1) You can run it by access the debug option in the main menu.
Start Debugging F5
Start Performance Analysis
Attach Unity Debugger
2) Click on the green play button on the tool bar
o0 curencyConverter -Microsot Visual Studio
File Edit View Project Build Debug Team Data Format Tools Test Analyze Window Help
10 Deb
3) Lastly just press F5
d Calaulate b
You will see this Screen. This is where all the programming codes go in. Our main priority of to convert the
currency user put in the boxes and return the converted value to them.
End Sub
End Class
Add the two highlighted lines in the button1_click function. We have created two double variables to store the
information from the text boxes. Text box 2 will hold the conversion rates and text box 3 holds the amount to be
converted. The reason we have created them as double is because normal integers cannot hold decimal
numbers.
Integers only hold 1, 2, 400, 321, 834298 etc. it cannot hold values such as 22.8 or 1.99 etc. this is why we need
to have a double variable.
End Sub
End Class
Lets create another double variable this one will hold the converted total of the amount. As you can see inside
the double variable we created called convertedTotal we are calculating it by conversionRate times by
totalAmount.
For this purpose 1 pound is equals to 2.50 dollars. So if we had 11 pounds to convert to dollars how much will
we have?
Label4.Text = "From" & TextBox1.Text &" at" &conversionRate &" to Pounds in the amount of " &
totalAmount &", Total is: "& convertedTotal
End Sub
End Class
Now here is the results line. In this line we are taking label4 and changing the text dynamically to suit our
purpose. As you can see first we are calling the label4.text which handles all the string inside the label. We will
change it to show for example "Converted from US at 2.50 to pounds in the amounts of 11 total is 27.50".
Courty
Amourt 11
Caicate
Result is accurate.
This is a working currency converter now. However this program will only convert every other currency to
POUND so we need a system where we can change between pound to others as well.
In order to that we will need to another textbox and then change the GUl to the following.
Curency Cervene Changed country to from
textBox4
Cacue
Taal
We have added another text box and label to the program and changed the value of country to "From" and the
other label to "To". Now we can manipulate the program to show which currency and from where it was
converted.
When you are making changes make sure you understand the changes I made to the GUI. Lets make some
changes to the code to reflect our new components.
Label4.Text ="From" &TextBox1.Text &" at "& conversionRate &" to "&TextBox4.Text &" in the amount of "
& totalAmount &", Total is: "& convertedTotal
Look at the highlighted code in the box. We are calling the value of text box 4 which is the TO information box in
the GUI. Now lets run the same calculation as before from US to UK rate is at 2.50 amount of 11
From US
Te UK
Amourt 11
Calculate
1.46 US Dollar
1 us Dellar
0 60 Bian Pound
2012 2013 2014 20Is 2016
74
Our program seems to be off by a few pence however you need to rememnber that the money exchange rates
are calculating with several decimal points now just 2. So overall the program works and it outputs the right
amount.
Lets look another flow chart with the new GUl settings.
start
Enter From
Currency
Enter To
Currency No
Enter
Conversion
Click
Enter Amount
calculate
Yes
Its stillthesame as it was before only added the Enter from currency and Enter to currency. The overall program
will work exactly as before.
Every program needs a help screen. Now time to add another button called help to the GUI.
Cunency Comeete
Fign
To
Canverson Fate
Anourt
Caice
Total:
Solution Explorer
currencyConverter
My Project
EForm1.vb
help.vb
IInside your solution explorer there is help.vb file. That is another form just
like the one we have been working on before. We will now right click on the help.vb
Seltien Espiores
currencyaverter
a MyPraet
Open
Open Wth..
Via Cede
Vie Designer Sh
Vew Cless Diagar
Eckude From Projecd
Cut Ctrte)
a Coey
Delete
Renarne
Piopetes At.Fnter
lclick on view designer.
This is the new empty form. It's time to add some helpful
tips here for the user right.
Let's add a label and call it help. And then add a text box.
help
Helo
D
See that little triangle on the corner of the text box. Click on that and select Multiline.
Help
TextBox Tasks
Multiline
Instead of writing a line in different labels we can do it this way. Much simpler.
Properties
TertBoxl System.Windows.Forme
Modifie Friend
Multiline True
PasswordCha
ReadOnly False
RightToleft No
ScrolBars None
ShortcutsEnal True
> Sze 256, 210
Tablndex 1
TabStop True
Tag
Tet ncakkuate.
In this application you can change currencies between countries.
Enter the country of the currency first
tt
Ente
e t e ch as the eday eschange rate of the currencies.
Enter the total amount to convert
Cick on calculate
13:03
24/05/016
Help
Double click on the help button.
End Sub
This code above will be added automatically. Now add the following code in the middle of the program.
Here we are creating a variable called helpScreen and then we are giving a data type of help. Remember when
we called that form help right it's the same one. We are stating that this helpScreen should be a new instance of
the help form which we created earlier. This way the program will make space in the memory for the new form
to be deployed to the screen.
Secondly we are calling our newly created helpScreen variable and accessing the built in function called show.
Lets test the prOgram noW.
eete0yty te ouwo
Canuern Rate
earrgt
Anourt
Cloierl
Okay then its all done and now gO make any changes you want to.
Hai 5?