12 Replies - 7290 Views - Last Post: 19 February 2010 - 01:29 PM Rate Topic: -----

#1 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Currency Conversion

Posted 18 February 2010 - 03:59 PM

I found this code on here while doing a search and would like to be able to use it but it was written in C and I dont know much about that (don't know that much about VB.NET either but trying to learn)

Dim from,to as integer 
select case cboConvertfrom.Text 
case "British - Pounds" : 
from=0.765811 
case "US - Dollars" : 
from=1 
end select 
 
 
select case cboConvertTo.Text 
case "British - Pounds" 
to=0.765811 
case "US - Dollars" 
to=1 
end select 
 
dim result as integer 
 
result=from/to * Convert.ToInt16(txtAmount.Text)



What I do have is a text box where a user enteres a desired number of US dollars to convert to three types of currency. I know how to convert the string entered to an integer so the calculation can take place. What I don't know how to do is modify the above code so that the results will show up in the correct text boxes after each calculation (yes I know I have to convert the integer back to text).

If someone could show me how to do the first Select Case I can figure the rest out. Thanks in advance for any help.

Project attached.

Attached File(s)


This post has been edited by majaro: 18 February 2010 - 04:17 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Currency Conversion

#2 xnn  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 227
  • Joined: 10-February 10

Re: Currency Conversion

Posted 18 February 2010 - 05:25 PM

Dim dFrom As Double = 0.0
Dim dTo As Double = 0.0

Select Case cboConvertfrom.Text
  Case "British - Pounds"
     dFrom = 0.765811
  Case "US - Dollars"
     dFrom = 1
End Select


Was This Post Helpful? 0
  • +
  • -

#3 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Re: Currency Conversion

Posted 18 February 2010 - 05:50 PM

View Postxnn, on 18 February 2010 - 04:25 PM, said:

Dim dFrom As Double = 0.0
Dim dTo As Double = 0.0

Select Case cboConvertfrom.Text
  Case "British - Pounds"
     dFrom = 0.765811
  Case "US - Dollars"
     dFrom = 1
End Select




Where does the string in " " come from? A label?
Was This Post Helpful? 0
  • +
  • -

#4 xnn  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 227
  • Joined: 10-February 10

Re: Currency Conversion

Posted 18 February 2010 - 06:09 PM

The .Text member of Combobox returns the item selected in the combo box, in this case either "British - Pounds" or "US - Dollars"
Was This Post Helpful? 0
  • +
  • -

#5 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Re: Currency Conversion

Posted 18 February 2010 - 06:48 PM

View Postxnn, on 18 February 2010 - 05:09 PM, said:

The .Text member of Combobox returns the item selected in the combo box, in this case either "British - Pounds" or "US - Dollars"

Thanks
Was This Post Helpful? 0
  • +
  • -

#6 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Re: Currency Conversion

Posted 18 February 2010 - 09:07 PM

View Postmajaro, on 18 February 2010 - 05:48 PM, said:

View Postxnn, on 18 February 2010 - 05:09 PM, said:

The .Text member of Combobox returns the item selected in the combo box, in this case either "British - Pounds" or "US - Dollars"

Thanks

What does this line do

result=from/to * Convert.ToInt16(txtAmount.Text)

Was This Post Helpful? 0
  • +
  • -

#7 xnn  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 227
  • Joined: 10-February 10

Re: Currency Conversion

Posted 18 February 2010 - 09:20 PM

By dividing from by To you are left with the conversion ratio for the set conversion. It then converts the text in the Amount textbox into a 16 bit integer and multiplies it by the calculated ratio. A double or float would be better to allow converting partial pounds or dollars. It then stores this factor in the variable result.

This post has been edited by xnn: 18 February 2010 - 09:21 PM

Was This Post Helpful? 0
  • +
  • -

#8 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Re: Currency Conversion

Posted 19 February 2010 - 10:54 AM

Im a little confused, where does the calculation happen? Say someone enteres 10 US Dollars; where in the examples above does the conversion take place?
Was This Post Helpful? 0
  • +
  • -

#9 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: Currency Conversion

Posted 19 February 2010 - 11:04 AM

result=from/to * Convert.ToInt16(txtAmount.Text)

that is the code.

(from_rate / to_rate) * money_amount

In either case why not tie the conversion rate to the combo item and you could cut down on alot of needless Select Case statements

Dim result as Single = 0.0

result = (CSng(cboConvertfrom.SelectedValue) / CSng(cboConvertTo.SelectedValue)) * CSng(txtAmount.text)


Was This Post Helpful? 0
  • +
  • -

#10 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Re: Currency Conversion

Posted 19 February 2010 - 11:20 AM

Ok now I am with you. What would you have to do (best approach) to convert more than one currency all at once?
Was This Post Helpful? 0
  • +
  • -

#11 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Re: Currency Conversion

Posted 19 February 2010 - 01:21 PM

Well I've got it working. Thanks to everyones help. One other question. Instead of hard coding the conversion values is there a way to automatically update the rates from a web site that isn't to complicated.
Was This Post Helpful? 0
  • +
  • -

#12 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: Currency Conversion

Posted 19 February 2010 - 01:23 PM

View Postmajaro, on 19 February 2010 - 02:21 PM, said:

Well I've got it working. Thanks to everyones help. One other question. Instead of hard coding the conversion values is there a way to automatically update the rates from a web site that isn't to complicated.

refer to post #9
Was This Post Helpful? 0
  • +
  • -

#13 majaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 17-February 10

Re: Currency Conversion

Posted 19 February 2010 - 01:29 PM

Not sure I follow your suggestion. Where in that post does it get updated rates?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1