BMI Calculator

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
HSteacher
Posts: 1
Joined: Tue Apr 02, 2019 5:37 pm

BMI Calculator

Post by HSteacher » Tue Apr 02, 2019 7:52 pm

Greetings,
I'm a high school teacher and I just worked through the BMI Calculator interactive tutorial but I'm having a problem. In the stack script I have the following code. When I go into the run mode, enter a height and weight, then click Calculate, I get the following error.
stack "BMI Calculator": execution error at line 7 (LCB Error in file json.lcb at line 65: syntax error: 1:0 unexpected end of input)
System info:
2012 iMac, Mac OS 10.14
LiveCode Community Plus 9.0.3

Any help is appreciated!
P.S. I replaced the period in the URL because the forum gave me the message "You can’t post image, email or url links. Please remove clinicalcalculator<dot>org". Even though I checked the "Do not automatically parse URLs" option

Code: Select all

function getBMI pHeight, pWeight
   put "http://api.clinicalcalculator<dot>org/bmi?" & \ 
         "height_in_m=" & pHeight & "&weight_in_kg=" & pWeight into tURL
   
   put url tURL into tJSON
   
   put JsonImport(tJSON) into tArray
   return round(tArray["result"]["value"])
end getBMI

Klaus
Posts: 12007
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: BMI Calculator

Post by Klaus » Tue Apr 02, 2019 8:29 pm

Hi HSteacher,

obvously the server involved in that example does not exist anymore!?
Therefore we get nothing in tJSON and obviously the "json.lcb" widget
does not like it and gives this error.

You need to have at least 10 postings before you can post links etc.


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7018
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: BMI Calculator

Post by dunbarx » Tue Apr 02, 2019 9:43 pm

Hi.

Welcome.

I would roll my own BMI calculator. It is a perfect starter project. You will get all the help you need right here.

Start with a new stack, one button and one field. Make it pretty later.

Craig Newman

mrcoollion
Posts: 576
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: BMI Calculator

Post by mrcoollion » Wed Apr 03, 2019 7:06 am

I agree with Craig ,

Here is the BMI formula. Have fun.....
BMI_Formula.png
BMI_Formula.png (3.07 KiB) Viewed 1784 times

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8008
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: BMI Calculator

Post by FourthWorld » Wed Apr 03, 2019 7:31 am

1. The formula is easy enough that you'll deliver a a better user experience calculating it locally, as Craig suggested.

2. As an exercise in API usage, it's useful for diagnostic practice. What happens when you try the URL in a browser?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Klaus
Posts: 12007
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: BMI Calculator

Post by Klaus » Wed Apr 03, 2019 7:41 am

When I tried/try this in a browser, Safari tells me that is cannot find the server.
That why i presumed the server to be down (or at least currently not available).

bogs
Posts: 4790
Joined: Sat Feb 25, 2017 10:45 pm

Re: BMI Calculator

Post by bogs » Wed Apr 03, 2019 10:07 am

Considering this tutorial is included in the IDE, I wonder if the problem should be reported as a bug.
*Edit - Elanor beat me to it :D
https://quality.livecode.com/show_bug.cgi?id=20572

She also posted the work around code -
Elanor 2017-12-14 14:35:52 GMT wrote: As a workaround to make the current stack work the getBMI function on the Stack Script can be replaced by

function getBMI pHeight, pWeight
return round((pWeight/pHeight)/pHeight)
end getBMI
2. As an exercise in API usage, it's useful for diagnostic practice. What happens when you try the URL in a browser?
It may be useful for diagnostic practice IF it were expected to not be working AND the tutorial informed you of that.

I think it far less useful for someone picking up the language as a new language, following what you would expect to be a working tutorial, and then coming upon the error with no explanation why.

I would think that would actually be very un-useful and probably confusing, or at the least very annoying and irritating to the new comer.
Image

Klaus
Posts: 12007
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: BMI Calculator

Post by Klaus » Wed Apr 03, 2019 11:34 am

Wonderful, so this is a known bug since october 2017! :?
Very encouraging for newcomers.

MaxV
Posts: 1577
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: BMI Calculator

Post by MaxV » Mon Apr 22, 2019 10:49 pm

mrcoollion wrote:
Wed Apr 03, 2019 7:06 am
I agree with Craig ,

Here is the BMI formula. Have fun.....

BMI_Formula.png
Yes, so the code would be:
########CODE to copy and paste with your mouse#######
function getBMI pHeight, pWeight
#if pHeight is in cm, then
put pHeight / 100 into pHeight
put pWeight / ((pHeight)^2) into temp
return round ( temp)
end getBMI
########END OF CODE generated by this livecode app: http://tinyurl.com/j8xf3xq ########
########Code tested with livecode 9.0.4-rc-2########
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”