vaibhav
vaibhav

Reputation: 21

how to use ConversionRate() function in CurrencyConvertion webservice?

I have included following webservice in my project

http://www.webservicex.net/CurrencyConvertor.asmx

There i got a function as ConversionRate() which takes parameters as follws

double Rate;
CurrencyConvertor ccs = new CurrencyConvertor();
Rate= ccs.ConversionRate(Currency.USD, Currency.INR);
lblResult.text=Rate.toString();

It works fine but, My application contains 2 textboxes where i want to manually show the conversion rates

I want to do as follows

Rate= ccs.ConversionRate(txtFromCurrency.text, txtToCurrency.text);
lblResult.text=Rate.toString();

so that application should atomatically convert rates and show in the lable

but ConversionRate() takes arguments as Currency.(Name of Currency)

Is there any method to send these textbox parameters to the function?

Upvotes: 1

Views: 419

Answers (1)

AxelEckenberger
AxelEckenberger

Reputation: 16926

OK, ConversionRate is an enumeration. For the sake of simplicitly I assume that your text boxes contain the tree letter acronym of the currency as defined by the web service. You can convert the text to the Currency enumeration by using the following code:

var curFrom = (Currency) Enum.Parse(typeof(Currency), txtFromCurrency.text, true);
var curTo = (Currency) Enum.Parse(typeof(Currency), txtToCurrency.text, true);

and then you can plug this values into the conversion Rate function

var rate = ccs.ConversionRate(curFrom, curTo);
lblResult.text = rate.toString();

Upvotes: 1

Related Questions