Newbie - Simple Desktop App
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Newbie - Simple Desktop App
Hello Everyone
just want to share to you my first simple desktop i made it while studying the LIVECODE.
i have a question regarding the DATE i was trying to get the age but i can't get it. i'm confuse in using the CONVERT if i'm not mistaken the formula is age = thisyear - yearofbirth.
here is the code i made from my simple desktop app: if i run, it keep displaying the year of birth not the age
global theFName
global theLName
global theYearBirth
global theYearToday
global theage
on mouseup
put field "FName" into theFName
put field "LName" into theLName
put field "BYear" into theYearBirth
put the date into theyeartoday
convert theyeartoday to dateitems
put item 1 of it into theyeartoday
put theyeartoday - theyearbirth into theage
answer Information "Your Name is" &&theFName && theLName &theage
end mouseup
just want to share to you my first simple desktop i made it while studying the LIVECODE.
i have a question regarding the DATE i was trying to get the age but i can't get it. i'm confuse in using the CONVERT if i'm not mistaken the formula is age = thisyear - yearofbirth.
here is the code i made from my simple desktop app: if i run, it keep displaying the year of birth not the age
global theFName
global theLName
global theYearBirth
global theYearToday
global theage
on mouseup
put field "FName" into theFName
put field "LName" into theLName
put field "BYear" into theYearBirth
put the date into theyeartoday
convert theyeartoday to dateitems
put item 1 of it into theyeartoday
put theyeartoday - theyearbirth into theage
answer Information "Your Name is" &&theFName && theLName &theage
end mouseup
Thank you & God Bless Everyone
Regards,
lemodizon
Regards,
lemodizon
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Newbie - Simple Desktop App
Hi.
You will get all this shortly. In the meantime, two things:
1- If you look at the form of the dateItems, you see it is a comma delimited list. You cannot do arithmetic, like subtraction, on a comma delimited list. You cannot subtract "3" from "4,5,6".
2- Do everything in seconds. This form of the convert command gives a universal baseline that you can do math on:
Step through this verbose handler. I hope you can see how to get the information you really want.
Craig Newman
You will get all this shortly. In the meantime, two things:
1- If you look at the form of the dateItems, you see it is a comma delimited list. You cannot do arithmetic, like subtraction, on a comma delimited list. You cannot subtract "3" from "4,5,6".
2- Do everything in seconds. This form of the convert command gives a universal baseline that you can do math on:
Code: Select all
on mouseUp
convert the date to seconds
put it into today
convert "2/3/2015" to seconds
put it into aWhileAgo
put today - aWhileAgo into secondsDifference
put secondsDifference / 86400 into dayDifference
put dayDifference / 365 into yearDifference
end mouseUp
Craig Newman
-
- Posts: 253
- Joined: Wed Aug 19, 2015 4:29 pm
Re: Newbie - Simple Desktop App
The seconds is probably the best way to do this, but for fun here's a one-liner that replicates the functionality of the original example (I think?)
edit: fixed
Code: Select all
answer "Your name is"&& fld "Fname" && fld "Lname" && "and you will be" && ((item 3 of the long date) - (fld "Byear")) && "at the end of the year" && (item 3 of the long date)
Last edited by ClipArtGuy on Fri Apr 27, 2018 12:59 am, edited 6 times in total.
Re: Newbie - Simple Desktop App
Hi lemodizon,
you made a little mistake here:
Then the rest of the script will work as exspected.
Best
Klaus
you made a little mistake here:
Code: Select all
...
convert theyeartoday to dateitems
## IT is empty at this point!
## put item 1 of it into theyeartoday
## You need to use the, now converted, variable again -> theyeartoday
put item 1 of theyeartoday into theyeartoday
...
Best
Klaus
Re: Newbie - Simple Desktop App
hello thanks for sharing i tried your script it works in the first run but the second run i tried there is error
executing at 10:21:26 AM
Type Operators -: error in right operand
Object introduceButton
Line answer "Your name is"&& fld "Fname" && fld "Lname" && "and you will be" && ((item 3 of the long date) - (fld "Byear")) && "at the end of the year" && (item 3 of the long date)
Hint mouse
i have experienced the code that i posted in this forum is working before. in spite of i didn't get the age but now i run it again there is error. that i didn't experienced while i'm making my application before i post it here hmmm weird
executing at 10:21:26 AM
Type Operators -: error in right operand
Object introduceButton
Line answer "Your name is"&& fld "Fname" && fld "Lname" && "and you will be" && ((item 3 of the long date) - (fld "Byear")) && "at the end of the year" && (item 3 of the long date)
Hint mouse
i have experienced the code that i posted in this forum is working before. in spite of i didn't get the age but now i run it again there is error. that i didn't experienced while i'm making my application before i post it here hmmm weird
Thank you & God Bless Everyone
Regards,
lemodizon
Regards,
lemodizon
Re: Newbie - Simple Desktop App
Thanks everyone just want to share the updated desktop app i solved the age calculation date thanks guys for sharing and i'm happy coz little by little i'm getting to know more livecode...
here's my updated code it's quite long for newbie hehehehe but i'm having fun
global theFName
global theLName
global theYearBirth
global theSystemDate
global getYear
global myAge
on mouseup
switch
case field "FName" is empty
case field "LName" is empty
case field "YearBirth" is empty
beep
answer "Please fill up the fields"
break
default
put field "FName" into theFName
put field "LName" into theLName
put field "YearBirth" into theYearBirth
put the system date into thesystemdate
convert thesystemdate to dateitems
put item 1 of thesystemdate into getYear
put getyear - field"YearBirth" into myAge
Answer Information "Your name is" && field"FName" &&field"LName" &&"and your age is"&&myage &&"this year of" &&getyear
end switch
end mouseup
thanks everyone i'm in my next exercise
Keep Supporting Livecode!
here's my updated code it's quite long for newbie hehehehe but i'm having fun
global theFName
global theLName
global theYearBirth
global theSystemDate
global getYear
global myAge
on mouseup
switch
case field "FName" is empty
case field "LName" is empty
case field "YearBirth" is empty
beep
answer "Please fill up the fields"
break
default
put field "FName" into theFName
put field "LName" into theLName
put field "YearBirth" into theYearBirth
put the system date into thesystemdate
convert thesystemdate to dateitems
put item 1 of thesystemdate into getYear
put getyear - field"YearBirth" into myAge
Answer Information "Your name is" && field"FName" &&field"LName" &&"and your age is"&&myage &&"this year of" &&getyear
end switch
end mouseup
thanks everyone i'm in my next exercise
Keep Supporting Livecode!
Thank you & God Bless Everyone
Regards,
lemodizon
Regards,
lemodizon
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Newbie - Simple Desktop App
Hi.
Bravo.
A couple of comments.
- You do not need any globals, unless you plan on using them later in other handlers. Maybe you know this.
- You should exit the handler explicitly if one or more fields are empty. I find this more readable. This may be a matter of style, but check out this handler, derived from yours, just so you see another take on the method.
It may seem unimportant now, but notice the internal capitalization and use of spaces in my handler. I strongly suggest you adopt this convention. It makes it easier for both you and the rest of the world to read your code.
Oh, yes. Bravo
Craig
Bravo.
A couple of comments.
- You do not need any globals, unless you plan on using them later in other handlers. Maybe you know this.
- You should exit the handler explicitly if one or more fields are empty. I find this more readable. This may be a matter of style, but check out this handler, derived from yours, just so you see another take on the method.
Code: Select all
on mouseUp
if field "FName" is empty or fld "LName" is empty or fld "yearBirth" is empty then
answer "Please fill up the fields"
exit to top
end if
put the system date into theSystemDate
convert theSystemDate to dateitems
put item 1 of theSystemDate into getYear
put getYear - field "yearBirth" into myAge
answer "Your name is" && field "FName" && field "LName" && "and your age is" && myAge && "this year of" && getYear
end mouseUp
Oh, yes. Bravo
Craig
Re: Newbie - Simple Desktop App
dunbarx wrote: ↑Fri Apr 27, 2018 2:24 pmHi.
Bravo.
A couple of comments.
- You do not need any globals, unless you plan on using them later in other handlers. Maybe you know this.
- You should exit the handler explicitly if one or more fields are empty. I find this more readable. This may be a matter of style, but check out this handler, derived from yours, just so you see another take on the method.It may seem unimportant now, but notice the internal capitalization and use of spaces in my handler. I strongly suggest you adopt this convention. It makes it easier for both you and the rest of the world to read your code.Code: Select all
on mouseUp if field "FName" is empty or fld "LName" is empty or fld "yearBirth" is empty then answer "Please fill up the fields" exit to top end if put the system date into theSystemDate convert theSystemDate to dateitems put item 1 of theSystemDate into getYear put getYear - field "yearBirth" into myAge answer "Your name is" && field "FName" && field "LName" && "and your age is" && myAge && "this year of" && getYear end mouseUp
Oh, yes. Bravo
Craig
Thanks for the advice and i will try your revised code to my exercise. i used the global to stored the data i input in the fields i just followed the sample from the net regarding variables. what i'm doing i will look sample desktop app from different programing language and i will try to do it in livecode as a challenge to me then i will posted it the code from the tips and advice from you guys it helped me that there is other way to declare or to do that and i really appreciated for sharing your knowledge and please bare with me if sometimes i'm importunate to my questions. that's why i decided to post my first exercise aside from reading regarding livecode.in that case when i got it done or right it boost my confidence that Livecode can do that
thanks for the advice in correcting me in writing codes in livecode. see you guys in my next exercises.
Go Livecode and to all livecode developers job well done coz you're a great help to those newbie and others who wants to learn livecode.
Thank you & God Bless Everyone
Regards,
lemodizon
Regards,
lemodizon
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Newbie - Simple Desktop App
Write back as often as you like.
Start adding functionality to your app. It does not matter what form that might take, or whether any of it is useful or not. The building and coding of the extra gadgets is what you are interested in.
Get going.
Craig
Start adding functionality to your app. It does not matter what form that might take, or whether any of it is useful or not. The building and coding of the extra gadgets is what you are interested in.
Get going.
Craig
Re: Newbie - Simple Desktop App
Yes, and please keep in mind that there is only a certain quota of "smileys" allocated to each forum member!
Re: Newbie - Simple Desktop App
Last bumped by lemodizon on Fri Mar 08, 2019 12:42 am.