You are viewing our Forum Archives. To view or take place in current topics click here.
VB.NET 2010 Currency Converter
Posted:

VB.NET 2010 Currency ConverterPosted:

Champz
  • Rising Star
Status: Offline
Joined: Aug 27, 201013Year Member
Posts: 789
Reputation Power: 64
Status: Offline
Joined: Aug 27, 201013Year Member
Posts: 789
Reputation Power: 64
Hey guys,

I'm kind of a noob and I'm having trouble creating a currency converter that converts USD to Euros, GBP, and Pesos. It's supposed to display all 3 new currencies at the same time and the code isn't supposed to have "if" or any other logical statements.

If anyone can help me out, it would be much appreciated.
#2. Posted:
AxonGrab
  • New Member
Status: Offline
Joined: Mar 08, 201311Year Member
Posts: 26
Reputation Power: 1
Status: Offline
Joined: Mar 08, 201311Year Member
Posts: 26
Reputation Power: 1
You can do this using Google Converter.

For example, if you wanted to change $20 into GBP, this is how you'd do it.


http://www.google.com/ig/calculator?hl=en&q=20USD%3D%3FGBP


You could then use web requests to read the correct part of the string.[/code]
#3. Posted:
iyop45
  • Prospect
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
Status: Offline
Joined: Apr 15, 201113Year Member
Posts: 614
Reputation Power: 83
AxonGrab wrote You can do this using Google Converter.

For example, if you wanted to change $20 into GBP, this is how you'd do it.


http://www.google.com/ig/calculator?hl=en&q=20USD%3D%3FGBP


You could then use web requests to read the correct part of the string.[/code]


I think that's a pretty cheap way of doing it and isn't really making a currency converter.

Though back to the question, you got to understand that currency rates fluctuate a lot so it would be difficult to get the most accurate conversion at a point in time. Your best bet is to just follow some pre-written algorithms; so for a rough example the ratios between values as 1GP pound (ttg filter pound signs...) is roughly 2x more valuable than 1$ (as an example).

It's really simple maths but, I'll give you an idea; If the user goes for pounds to dollars conversion just multiply by 1.51, If pounds to dollars multiply by 0.66 etc etc simply ratios.
#4. Posted:
Champz
  • Rising Star
Status: Offline
Joined: Aug 27, 201013Year Member
Posts: 789
Reputation Power: 64
Status: Offline
Joined: Aug 27, 201013Year Member
Posts: 789
Reputation Power: 64
I'm having trouble with the actual code and I need to make a GUI for this as well (obviously lol). The rates don't really matter because I can just use xe.com and change them later.

Also, I can't use any shortcuts. Everything I need has to be created in the program, except for the rates from [ Register or Signin to view external links. ] .
#5. Posted:
AxonGrab
  • New Member
Status: Offline
Joined: Mar 08, 201311Year Member
Posts: 26
Reputation Power: 1
Status: Offline
Joined: Mar 08, 201311Year Member
Posts: 26
Reputation Power: 1
iyop45 wrote
AxonGrab wrote You can do this using Google Converter.

For example, if you wanted to change $20 into GBP, this is how you'd do it.


http://www.google.com/ig/calculator?hl=en&q=20USD%3D%3FGBP


You could then use web requests to read the correct part of the string.[/code]


I think that's a pretty cheap way of doing it and isn't really making a currency converter.

Though back to the question, you got to understand that currency rates fluctuate a lot so it would be difficult to get the most accurate conversion at a point in time. Your best bet is to just follow some pre-written algorithms; so for a rough example the ratios between values as 1GP pound (ttg filter pound signs...) is roughly 2x more valuable than 1$ (as an example).

It's really simple maths but, I'll give you an idea; If the user goes for pounds to dollars conversion just multiply by 1.51, If pounds to dollars multiply by 0.66 etc etc simply ratios.


Although it is a cheap way of doing it, this compensates for the influxes as Google are always up to date. It also means, someone who is quit obviously new doesn't have to write a complex algorithm and can instead just create the project at hand.
#6. Posted:
UnrealEgg
  • Powerhouse
Status: Offline
Joined: May 30, 201013Year Member
Posts: 438
Reputation Power: 49
Status: Offline
Joined: May 30, 201013Year Member
Posts: 438
Reputation Power: 49
There isn't anything particularly difficult about this presuming you don't want extremely high accuracy.

As suggested previously, you could parse the [ Register or Signin to view external links. ] to get a conversion rate or even the answer. Alternatively, you would simply have a text boxes that the user can enter the current exchange rate.

If you were to use Google to get the exchange rate then calculate the rest your self, just make sure its a 1:1 ratio.

Then you would have a further text boxes, one for the current currency, then others for the target currencys. You could then write the function (below) and hook it up to the text changed event on the currenct currency text box.

Your code for the conversion would be something like (as iyop45 suggested):
targetCurrency.Text = currentCurrency.Text * exchangeRate.Text (or variable if parsed from Google)

Math side:
23.21416727 (GBP) = 35 (USD) * 0.663261922;

In terms of not having an if statement, you could do several functions like "toEUR()", "toGBP()" so when it comes to the text updating, you would simply set the text box values by doing something like:
gbpCurrency.Text = toGBP();
eurCurrenct.Text = toEUR();

Hopefully that's close to what you're after.
#7. Posted:
-CJHaCKerZz-
  • Resident Elite
Status: Offline
Joined: Nov 05, 201112Year Member
Posts: 232
Reputation Power: 11
Status: Offline
Joined: Nov 05, 201112Year Member
Posts: 232
Reputation Power: 11
You need to double click the input textbox and it will create a function of textChanged...

Now type something like this:

Dim uk as Integer = TextBoxUK.text()
Dim us as Double = 0.66
Dim Result as Integer = uk * us
TextBoxResult.appendText(Result)

(This code may not work as I no longer program in VB)
(0.66 = dollars to pounds exchange rate by the way..)
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.