Newbie - Simple Desktop App

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
lemodizon
Posts: 175
Joined: Thu Apr 05, 2018 3:33 pm

Newbie - Simple Desktop App

Post by lemodizon » Thu Apr 26, 2018 5:46 pm

Hello Everyone :D :D :D

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
Attachments
MySimpleApp.png
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

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

Re: Newbie - Simple Desktop App

Post by dunbarx » Thu Apr 26, 2018 8:38 pm

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:

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
Step through this verbose handler. I hope you can see how to get the information you really want.

Craig Newman

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: Newbie - Simple Desktop App

Post by ClipArtGuy » Thu Apr 26, 2018 9:11 pm

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?)

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)
edit: fixed
Last edited by ClipArtGuy on Fri Apr 27, 2018 12:59 am, edited 6 times in total.

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

Re: Newbie - Simple Desktop App

Post by Klaus » Thu Apr 26, 2018 9:42 pm

Hi lemodizon,

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 
...
Then the rest of the script will work as exspected.


Best

Klaus

lemodizon
Posts: 175
Joined: Thu Apr 05, 2018 3:33 pm

Re: Newbie - Simple Desktop App

Post by lemodizon » Fri Apr 27, 2018 3:27 am

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 :?
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

lemodizon
Posts: 175
Joined: Thu Apr 05, 2018 3:33 pm

Re: Newbie - Simple Desktop App

Post by lemodizon » Fri Apr 27, 2018 8:59 am

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 :D :D :D :D

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! :D :D :D
Attachments
MyUpdated_Desktop_App.png
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

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

Re: Newbie - Simple Desktop App

Post by dunbarx » Fri Apr 27, 2018 2:24 pm

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.

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
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

lemodizon
Posts: 175
Joined: Thu Apr 05, 2018 3:33 pm

Re: Newbie - Simple Desktop App

Post by lemodizon » Sat Apr 28, 2018 1:37 pm

dunbarx wrote:
Fri Apr 27, 2018 2:24 pm
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.

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
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

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 :D :D :D 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. :D :D :D
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

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

Re: Newbie - Simple Desktop App

Post by dunbarx » Sat Apr 28, 2018 5:12 pm

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

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

Re: Newbie - Simple Desktop App

Post by Klaus » Sat Apr 28, 2018 5:23 pm

Yes, and please keep in mind that there is only a certain quota of "smileys" allocated to each forum member!

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

Re: Newbie - Simple Desktop App

Post by Klaus » Sat Apr 28, 2018 5:23 pm

:D :D :D

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

Re: Newbie - Simple Desktop App

Post by bogs » Fri Mar 08, 2019 12:42 am

My quota is 'EXTRA High'
ImageImage


Last bumped by lemodizon on Fri Mar 08, 2019 12:42 am.
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”