• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Is it possible to simplify this code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is it possible to simplify this code?


  • Subject: Is it possible to simplify this code?
  • From: Brian Christmas <email@hidden>
  • Date: Thu, 11 Aug 2011 13:22:58 +1000


G'day Scripters.

I now have a very elegant pop-up sheet with 9 item on it, but my next one needs 33!!

It would be excellent if I did not have to type in 33 items of code to set an array and corresponding images.

I've tried using (sender) as a reference where the array items were named the same as the sending items, but it did not work.

ie

if sender = setSunday then
            if theHoldingDaysArray's sender = false then
             set theHoldingDaysArray's sender to true
            else
            set theHoldingDaysArray's sender to false 
end if
        

Where the array was 'set theHoldingArray to {setSunday:false}' and the controller name was set to 'setSunday'

Any takers on the matter, or have I got a lot of typing to do?

Regards

Santa







  -- ________________  Sets up theDays data (an Array as part of arrangedObjects) _________________

  

    on setAllTheDays_(sender)
         if sender = setDaysFinished then 
          setTheDaysWindow's orderOut_(me)

 

        end if
        if sender = setEveryDay then 
             if theHoldingDaysArray's setEveryDayStore=false then 
                 set theHoldingDaysArray's setEveryDayStore to true 
                 set theHoldingDaysArray's setSundayStore to true
                 set theHoldingDaysArray's setMondayStore to true
                 set theHoldingDaysArray's setTuesdayStore to true 
                 set theHoldingDaysArray's setWednesdayStore to true  
                 set theHoldingDaysArray's setThursdayStore to true  
                 set theHoldingDaysArray's setFridayStore to true  
                 set theHoldingDaysArray's setSaturdayStore  to true 
                 set temp to my displaySetAllTheDays_()
                 else
                 set theHoldingDaysArray's setEveryDayStore to false 
                my  displaySetAllTheDays_()
             end if     
          end if
    if theHoldingDaysArray's setEveryDayStore=false
        set theDaysCheckFlag to false
        if sender = setSunday then
            if theHoldingDaysArray's setSundayStore = false then
             set theHoldingDaysArray's setSundayStore to true
            else
            set theHoldingDaysArray's setSundayStore to false 
         end if
        end if
        if sender = setMonday then 
             if theHoldingDaysArray's setMondayStore  = false then
                 set theHoldingDaysArray's setMondayStore  to true
            else
                 set theHoldingDaysArray's setMondayStore to false 
         end if
        end if
        if sender = setTuesday then 
            if theHoldingDaysArray's setTuesdayStore = false then
             set theDaysCheckFlag to true
            else
            set theHoldingDaysArray's setTuesdayStore to false 
         end if
        end if
        if sender = setWednesday then
            if theHoldingDaysArray's setWednesdayStore = false then
             set theHoldingDaysArray's setWednesdayStore to true
            else
             set theHoldingDaysArray's setWednesdayStore to false
         end if
        end if
        if sender = setThursday then
            if theHoldingDaysArray's setThursdayStore = false then
             set theHoldingDaysArray's setThursdayStore to true
             else
            set theHoldingDaysArray's setThursdayStore to false
         end if
        end if
        if sender = setFriday then
           if theHoldingDaysArray's setFridayStore = false then
             set theHoldingDaysArray's setFridayStore to true
            else
             set theHoldingDaysArray's setFridayStore to false
         end if
        end if
        if sender = setSaturday then
            if theHoldingDaysArray's setSaturdayStore = false then
             set theHoldingDaysArray's setSaturdayStore to true
            else
            set theHoldingDaysArray's setSaturdayStore to false
            end if
        end if
        set theDaysCheckFlag to my displaySetAllTheDays_()
            if not theDaysCheckFlag then
            my sayTheSoundError_("You must have at least one day set.",true)
            my setAllTheDays_(setEveryDay)
            end if
    end if
end setAllTheDays

    

on displaySetAllTheDays_()
   set theDaysCheckFlag to false
    if theHoldingDaysArray's setEveryDayStore=true then 
         setEveryDay's setImage_forSegment_(greenCircle,0)
        set theDaysCheckFlag to true
        else
        setEveryDay's setImage_forSegment_(redCircle,0)
     end if   
    if theHoldingDaysArray's setSundayStore = true then
        setSunday's setImage_forSegment_(greenCircle,0)
    set theDaysCheckFlag to true
    else
        setSunday's setImage_forSegment_(redCircle,0)
    end if
    if theHoldingDaysArray's setMondayStore  = true then
    setMonday's setImage_forSegment_(greenCircle,0)
set theDaysCheckFlag to true
else
    setMonday's setImage_forSegment_(redCircle,0)
     end if
    if theHoldingDaysArray's setTuesdayStore = true then
    setTuesday's setImage_forSegment_(greenCircle,0)
set theDaysCheckFlag to true
else
    setTuesday's setImage_forSegment_(redCircle,0)
    end if
      if theHoldingDaysArray's setWednesdayStore = true then
    setWednesday's setImage_forSegment_(greenCircle,0)
set theDaysCheckFlag to true
else
    setWednesday's setImage_forSegment_(redCircle,0)
     end if
      if theHoldingDaysArray's setThursdayStore = true then
    setThursday's setImage_forSegment_(greenCircle,0)
set theDaysCheckFlag to true
else
    setThursday's setImage_forSegment_(redCircle,0)
     end if
     if theHoldingDaysArray's setFridayStore = true then
    setFriday's setImage_forSegment_(greenCircle,0)
set theDaysCheckFlag to true
else
    setFriday's setImage_forSegment_(redCircle,0)
    end if
      if theHoldingDaysArray's setSaturdayStore = true then
    setSaturday's setImage_forSegment_(greenCircle,0)
set theDaysCheckFlag to true
else
    setSaturday's setImage_forSegment_(redCircle,0)
     end if
return theDaysCheckFlag
end displaySetAllTheDays_
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: How do I set up image in segmented controller?
  • Next by Date: Re: Is it possible to simplify this code?
  • Previous by thread: Re: How do I set up image in segmented controller?
  • Next by thread: Re: Is it possible to simplify this code?
  • Index(es):
    • Date
    • Thread