Need help with this.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Curiousbystander
Posts: 20
Joined: Wed Sep 07, 2022 4:26 pm

Need help with this.

Post by Curiousbystander » Wed Nov 23, 2022 8:45 am

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

Curiousbystander
Posts: 20
Joined: Wed Sep 07, 2022 4:26 pm

Re: Need help with this.

Post by Curiousbystander » Wed Nov 23, 2022 9:06 am

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Need help with this.

Post by richmond62 » 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

Curiousbystander
Posts: 20
Joined: Wed Sep 07, 2022 4:26 pm

Re: Need help with this.

Post by Curiousbystander » Wed Nov 23, 2022 9:17 am

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Need help with this.

Post by richmond62 » Wed Nov 23, 2022 9:19 am

Screen Shot 2022-11-23 at 10.21.21 AM.png
-
Attachments
Drop Down.livecode.zip
Stack.
(991 Bytes) Downloaded 149 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Need help with this.

Post by richmond62 » 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.

Curiousbystander
Posts: 20
Joined: Wed Sep 07, 2022 4:26 pm

Re: Need help with this.

Post by Curiousbystander » Wed Nov 23, 2022 9:26 am

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Need help with this.

Post by richmond62 » Wed Nov 23, 2022 10:11 am

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.

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Need help with this.

Post by AndyP » Wed Nov 23, 2022 10:16 am

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.
Attachments
Screenshot 2022-11-23 101531.png
Andy .... LC CLASSIC ROCKS!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Need help with this.

Post by richmond62 » Wed Nov 23, 2022 10:31 am

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
Attachments
Drop Down2.livecode.zip
Stack.
(7.94 KiB) Downloaded 132 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10096
Joined: Fri Feb 19, 2010 10:17 am

Re: Need help with this.

Post by richmond62 » Wed Nov 23, 2022 10:33 am

Use AndyP's method of getting the conversion rates, and then
use what I have shown you to do the conversions.

Post Reply