tags:

views:

44

answers:

1

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?

+1  A: 

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();
Obalix
I added the following code in my application Currency CurFrom = new Currency(); Currency CurTo= new Currency(); CurFrom = Enum.Parse(typeof(Currency), txtFromCurrency.Text, true); CurTo = Enum.Parse(typeof(Currency), txtToCurrency.Text, true); CurrencyConvertor ccs = new CurrencyConvertor(); Rate= ccs.ConversionRate(CurFrom,CurTo); lblResult.Text = Rate.ToString();It shows follwoing error can not implectly convert object to CurrencyConverstion.Currency
vaibhav
Then cast explicitly by adding (Currency). Like this:(Currency)(Enum.Parse(typeof(Currency), txtToCurrency.text, true));
citronas
@citronas: Thanks, forgot about that.
Obalix
Thanks that works
vaibhav
@vaibhav: Accepting the answer would be greatly appreciated.
Obalix