Best viewed in Firefox

Awesty Productions

Make a Currency Converter in Visual Basic 2005

June 15th, 2007 by awesty

In this tutorial you will learn how to make a simple currency converter. This is a great tutorial if you are just starting out with Visual Basic. If you haven’t already, you need to download Visual Basic 2005 for free and install it.

First of all you need to open Visual Basic 2005. Hit Ctrl+N or File>New Project. Select ‘Windows Application’. You should see a screen that looks something like this.

The opening screen

If the toolbox is not already open hit Ctrl+Alt+X to open it. Put 3 radio buttons, 3 text boxes and 1 button onto the form. To do this you cab double click the items in the toolbox or drag them on. Rearrange them so they look something like this.


Select RadioButton1 and change the following values in the properties window. (Name): RadioUSD, Checked:True, Text:&USD.
The first radio button should now be selected and instead of being called RadioButton1, it should have USD. The U is underlined so the user can just press Alt+U to select it. Do the same for the other two radio buttons, but with the following values.

RadioButton2: (Name): RadioAUD, Text: &AUD

RadioButton3: (Name): RadioGBP, Text: &GBP

Now select the text box opposite the USD radio button. In the properties panel change the name value to ResultUSD. Do the same for the other two text boxes, but instead of calling them ResultUSD call them ResultAUD and ResultGBP, depending on which radio button they are opposite to.

Select the button and change the following values in the properties panel. (Name): Convert, Text: Convert.

Double click on the Convert button. It should bring up a screen with a bit on code on it. This is where you do all the programming. When you use the code I give you put it between the:

Public Class CurConvert

    Private Sub Convert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Convert.Click

And the

End Sub
End Class

Here is the code:

       If (RadioUSD.Checked = True) Then
            If (IsNumeric(ResultUSD.Text) = True) Then
                ResultAUD.Text = (Val(ResultUSD.Text) * 1.1875)
                ResultGBP.Text = (Val(ResultUSD.Text) * 0.507)
            ElseIf (ResultUSD.Text = "") Then
                ResultAUD.Text = "Please enter a value"
                ResultGBP.Text = "Please enter a value"
            Else
                ResultAUD.Text = "Numbers only please"
                ResultGBP.Text = "Numbers only please"
            End If

        End If

        If (RadioAUD.Checked = True) Then
            If (IsNumeric(ResultAUD.Text) = True) Then
                ResultUSD.Text = (Val(ResultAUD.Text) * 0.842)
                ResultGBP.Text = (Val(ResultAUD.Text) * 0.4269)
            ElseIf (ResultAUD.Text = "") Then
                ResultGBP.Text = "Please enter a value"
                ResultUSD.Text = "Please enter a value"
            Else
                ResultGBP.Text = "Numbers only please"
                ResultUSD.Text = "Numbers only please"
            End If
        End If

        If (RadioGBP.Checked = True) Then
            If (IsNumeric(ResultGBP.Text) = True) Then
                ResultAUD.Text = (Val(ResultGBP.Text) * 2.342)
                ResultUSD.Text = (Val(ResultGBP.Text) * 1.972)
            ElseIf (ResultGBP.Text = "") Then
                ResultAUD.Text = "Please enter a value"
                ResultGBP.Text = "Please enter a value"
            Else
                ResultAUD.Text = "Numbers only please"
                ResultGBP.Text = "Numbers only please"
            End If
        End If

Now hit the ‘Start debugging’ () button to see your first Visual Basic program come to life.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • del.icio.us
  • digg
  • Furl
  • MyShare
  • NewsVine
  • Netscape
  • Reddit
  • Simpy
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

RSS feed | Trackback URI

9 Comments »

Comment by Eibwen Subscribed to comments via email
2007-06-16 11:12:35

It would be better if you had VB6. :P

 
Comment by morti Subscribed to comments via email
2007-06-17 00:36:32

cool. I wanna learn VB atm so can you do some more (simple) tuts
thanks

Comment by awesty
2007-06-17 11:50:45

Yea, I will try.

 
 
Comment by Eibwen Subscribed to comments via email
2007-06-18 02:13:53

I’ll help you out.

[code]Private Sub Command1_Click()
End
End Sub[/code]
This code closes the program.

 
Comment by Freddy Subscribed to comments via email
2008-01-17 19:41:22

Not much of a turoial, as it’s mostly . Tut

 
Comment by Freddy Subscribed to comments via email
2008-01-17 19:51:56

Not much of a turoial, as it’s mostly copy and paste. Tut

 
Comment by fgh Subscribed to comments via email
2008-06-05 10:00:25

If (RadioUSD.Checked = True) Then
If (IsNumeric(ResultUSD.Text) = True) Then
ResultAUD.Text = (Val(ResultUSD.Text) * 1.1875)
ResultGBP.Text = (Val(ResultUSD.Text) * 0.507)
ElseIf (ResultUSD.Text = “”) Then
ResultAUD.Text = “Please enter a value”
ResultGBP.Text = “Please enter a value”
Else
ResultAUD.Text = “Numbers only please”
ResultGBP.Text = “Numbers only please”
End If

End If

If (RadioAUD.Checked = True) Then
If (IsNumeric(ResultAUD.Text) = True) Then
ResultUSD.Text = (Val(ResultAUD.Text) * 0.842)
ResultGBP.Text = (Val(ResultAUD.Text) * 0.4269)
ElseIf (ResultAUD.Text = “”) Then
ResultGBP.Text = “Please enter a value”
ResultUSD.Text = “Please enter a value”
Else
ResultGBP.Text = “Numbers only please”
ResultUSD.Text = “Numbers only please”
End If
End If

If (RadioGBP.Checked = True) Then
If (IsNumeric(ResultGBP.Text) = True) Then
ResultAUD.Text = (Val(ResultGBP.Text) * 2.342)
ResultUSD.Text = (Val(ResultGBP.Text) * 1.972)
ElseIf (ResultGBP.Text = “”) Then
ResultAUD.Text = “Please enter a value”
ResultGBP.Text = “Please enter a value”
Else
ResultAUD.Text = “Numbers only please”
ResultGBP.Text = “Numbers only please”
End If
End If

 
Comment by priyanka Subscribed to comments via email
2008-07-06 18:29:50

hey everyone…..
i want 2 make a project for my assignment……..n m making on atm(automated teller machine)
i had successfully designed d forms but m damm confused for its coding……….i jst want sum code 2 update d account bal if i withdraw or debit d amount of account bal……plzz help me out
waiting 4 d needful help

regards

Comment by priyanka Subscribed to comments via email
2008-07-16 04:08:04

is there no one 2 help me out……………………

 
 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> in your comment.