Convert

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Convert

Post by TKYTKY » Thu Jul 18, 2013 3:35 am

Hi guys

Please help. Really confuse with livecode.

I have to convert this text into a survey format in livecode but i dont know how to start.

Any suggestion / examples ?


{"survey_id": "1", "survey_title": "An exmaple of Pesonal Health Assessment Survey","questions":[{ "id": "Q1", "question": "I eat at fast food restaurant less than 3 times per week", "ans": [{"choice": "Strongly Agree"}, {"choice": "Agree"}, {"choice": "Neither Agree or Disagree"},{"choice": "Disgree"}, {"choice": "Strongly Disgree"}] },{ "id": "Q2", "question": "I eat at least 2 servings of vegetable everyday", "ans": [{"choice": "Strongly Agree"}, {"choice": "Agree"}, {"choice": "Neither Agree or Disagree"},{"choice": "Disgree"}, {"choice": "Strongly Disgree"}] },{ "id": "Q3", "question": "My favourite form of exercise", "ans": [{"choice": "Walking"}, {"choice": "Jogging"}, {"choice": "Yoga"}, {"choice": "Cycling"},{"choice": "Swimming"}, {"choice": "Others"}, {"choice": "I dont exercise"}] }]}

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Convert

Post by Simon » Thu Jul 18, 2013 4:30 am

Hi tkytky,
Do you know what "Parsing" is?
Sorry if it's a dumb question but it's what you'll be doing.

With a new stack drag a text entry field and a button onto it.
Paste your info into the field.
In the button code put:

Code: Select all

on mouseUp
   put fld 1 into tVar
   replace quote with "" in tVar --remove all the junk
   replace "{" with "" in tVar
   replace ":" with "" in tVar
   replace "id" with cr & "id" in tVar --put a return at the start so I can read it
   put tVar into fld 1
end mouseUp
Now that's just to get you going, you'll see that I left a bunch of junk in that you can remove.

I think that replace with cr & "id" will give you a clue how to distinguish separate parts of the input for use in individual fields and radio buttons.

If you have questions just ask.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Convert

Post by dunbarx » Thu Jul 18, 2013 3:10 pm

Hi.

Simon has tried to organize your data.

But you must learn the basics of text handling in LiveCode. This is based on what is known as "chunking". You have to read the user guide and dictionary, learning what distinguishes "words", "items", "lines" and other stuff.

LC contains enormous power in its ability to parse data, as Simon mentioned, and this is usually fun to do, in that you build data structures that can be deconstructed as desired to create information. But you need the basic tools.

Craig Newman

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Convert

Post by TKYTKY » Fri Jul 19, 2013 3:21 am

Thanks

I know what is parsing but i dont know how it works in livecode. Reading book like LIVE REFERENCE and still not sure how to do it. Wanted to find sample online to guide me through but there`s no livecode sample on survey

Can anyone give me an example how to make this application out ?

1) I am suppose to get the survey question in JSON format from http://intimes.eu.pn/getsurvey.php
2) Display the survey out with proper form ( sumbitbutton/radio button)
3) send the survey answer back to the server

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Convert

Post by Simon » Fri Jul 19, 2013 3:32 am

Hi tkytky,
Did you try out the code I posted?
I though it took you to a logical end result.
Maybe I'm misunderstanding, happens all the time to me. Maybe tell me where it isn't what you wanted?
Is it that you want code for setting the radio button, question, title names?

Nope don't know of any examples.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Convert

Post by TKYTKY » Fri Jul 19, 2013 4:11 am

Hi simon

Thanks for the reply
I try out the code that you posted . It help tidy up the codes.
and ya i want code for setting the radio button , question number, title name and a sumbit button but how do i get it ?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Convert

Post by Simon » Fri Jul 19, 2013 5:21 am

Ahhh, thats a bit more than I should do.
I'd like to think of this forum as a learning center, not a place for free code.
But I'm happy to give you some more clues.

Code: Select all

replace "id" with cr & "id" in tVar
Did you see what that did? Now every question and possible answer is on it's own line.
From there you can then parse out more.
"Put line 2 of tVar into tQuest"
Now parse that.

On the other hand if you pay me, I'll parse the whole thing out for you. :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Convert

Post by Klaus » Sun Jul 21, 2013 4:18 pm

HI TKYTKY,

take a look at these stacks to get the basics of Liveocode:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Convert

Post by TKYTKY » Tue Jul 23, 2013 5:48 am

Thanks for the reply everyone

Simon do you have skype ? need some guide lines from you. And if i still cant do . might need you to do a sample for me . WIlll pay for that

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Convert

Post by Simon » Tue Jul 23, 2013 5:53 am

Wicked cool!
Where are you located?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

TKYTKY
Posts: 46
Joined: Thu Jul 11, 2013 9:25 am

Re: Convert

Post by TKYTKY » Tue Jul 23, 2013 5:59 am

Hi simon

I lived in singapore. can you private message me your skype ? i will try some solution and if i cant do them . i need your help

Post Reply