Page 1 of 1

Need help with this.

Posted: Wed Nov 23, 2022 8:45 am
by Curiousbystander
How would I go about making a currency converter.

I want to be able to choose currencies from NOK, euro, dollar and english pounds and convert whichever I want to choose.

I can choose whatever currency I want and it converts to the rest. Those 4 currencies are all I need, how would I make this

Re: Need help with this.

Posted: Wed Nov 23, 2022 9:06 am
by Curiousbystander
I want to have like a drop down menu where I can choose which currency I want to choose, and it converts to rest of them.

Would be great if anyone could help

Re: Need help with this.

Posted: Wed Nov 23, 2022 9:12 am
by richmond62
Just the same as you would make a temperature converter . . .
-
temps.jpg
-
. . . except you would, probably need a way to get the exchange rates from the internet.

Code inside button '∘C':

Code: Select all

on mouseUp
   put fld "fC" into CENTIG
   put (0.8 * CENTIG) into fld "fRe"
   put (((CENTIG / 5) * 9) + 32) into fld "fF"
   put (((CENTIG + 273.15) / 6) * 9) into fld "fRa"
end mouseUp

Re: Need help with this.

Posted: Wed Nov 23, 2022 9:17 am
by Curiousbystander
richmond62 wrote:
Wed Nov 23, 2022 9:12 am
Just the same as you would make a temperature converter . . .
-
temps.jpg
-
. . . except you would, probably need a way to get the exchange rates from the internet.

Code inside button '∘C':

Code: Select all

on mouseUp
   put fld "fC" into CENTIG
   put (0.8 * CENTIG) into fld "fRe"
   put (((CENTIG / 5) * 9) + 32) into fld "fF"
   put (((CENTIG + 273.15) / 6) * 9) into fld "fRa"
end mouseUp
Thanks, but I was expecting more like a drop down menu where I can choose the currency and choose also which one to convert to

Re: Need help with this.

Posted: Wed Nov 23, 2022 9:19 am
by richmond62
Screen Shot 2022-11-23 at 10.21.21 AM.png
-

Re: Need help with this.

Posted: Wed Nov 23, 2022 9:20 am
by richmond62
I was expecting more like a drop down menu where I can choose the currency and choose also which one to convert to
Possibly, but I am not going to do ALL your work for you.

Re: Need help with this.

Posted: Wed Nov 23, 2022 9:26 am
by Curiousbystander
richmond62 wrote:
Wed Nov 23, 2022 9:20 am
I was expecting more like a drop down menu where I can choose the currency and choose also which one to convert to
Possibly, but I am not going to do ALL your work for you.
I understand, I just need like a concept to work off on.

This is kind of what I am thinking about: https://www.youtube.com/watch?v=hnNMGKhnCxs

Re: Need help with this.

Posted: Wed Nov 23, 2022 10:11 am
by richmond62
If you combine what I showed you in the temperature conversion thing and the script
in the drop down stack you should find currency conversions extremely easy.

For instance, I live in Bulgaria, where the local currency (The Lev) is pegged against the Euro
at 1.91, so a simple algorithm converts money each way.

Re: Need help with this.

Posted: Wed Nov 23, 2022 10:16 am
by AndyP
This will give you a good start.

Go to the sample stacks search for json and download my JSON API Helper stack. Later place this in your plugins folder.

In the helper stack put https://api.exchangerate.host/latest into the JSON Source field and hit the Set TreeView to API IData button. This will load the exchange rates into the tree view.

Expand the rates in the tree view.
Click on the currencies you need and when the popup asks add them, answer Yes.

Once you have the currencies you need, hit the Create Script button.
The script generated will give you a good start, see if you can work out how to use a dropdown to access the code in the script.

Also hit the Test button to see the results of the generated script.


You can also try using this api endpoint https://api.exchangerate.host/convert?from=USD&to=EUR in the JSON API Helper, just change the currencies you need in the endpoint.

Re: Need help with this.

Posted: Wed Nov 23, 2022 10:31 am
by richmond62
Screen Shot 2022-11-23 at 11.32.18 AM.png
-

Code: Select all

on menuPick XXX
   switch XXX
      case "Kroner"
         put fld "fSTART" into MONEY
         put "NOK" & MONEY into fld "fKRONER"
         put "$" & MONEY/10.07 into fld "fDOLLAR"
         put "€" & MONEY/10.386 into fld "fEURO"
         put "£" & MONEY/11.98 into fld "fPOUND"
         break
      case "Dollar"
         
         break
   end switch
end menuPick

Re: Need help with this.

Posted: Wed Nov 23, 2022 10:33 am
by richmond62
Use AndyP's method of getting the conversion rates, and then
use what I have shown you to do the conversions.