Additional routines

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
MadDogDean
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 18
Joined: Thu Jan 03, 2013 6:33 pm
Location: Floating in the binary mist

Additional routines

Post by MadDogDean » Mon Jan 25, 2016 6:47 am

Hello all,

Here's a upgraded routine for those of you working on the Calculator course. Our observations:
1. A leading "." was not preceded by a leading zero (merely aesthetics)
2. It was possible to enter multiple "." in a number

Update the code on the Card Script

Code: Select all

on numberPressed pNumPress
   --if the text of field "display" is 0 then
   if lNewNumber is true then
      -- determine if we need a leading zero
      if pNumPress = "." then
         put "0" into field "display"
         put pNumPress after field "display"
         put false into lNewNumber
      else    
         put pNumPress into field "display"
         put false into lNewNumber
      end if
   else
      -- allow only one "."
      if pNumPress = "." then
         if field "display" contains "." then exit numberPressed
      end if
      put  pNumPress after field "display"
   end if
   set the label of button "clear" to "C"
   textUpdated
end numberPressed
Enjoy!
MadDogDean

Post Reply

Return to “Calculator”