2017-01-19 1 views
-1

나는 사람이 파일을 선택하도록 요구하는 프로그램을 만들고 그것을 확인하려고 노력 중이다. if 블록에 반복을 추가하려고 할 때 문제가 발생했습니다. 이것이 매우 실망 스럽기 때문에 이에 대한 해결 방법이 있습니까? 미리 감사드립니다! :)if 블록에서 반복 하시겠습니까?

display dialog "Select the program" 

tell application "Finder" 

set filePath to POSIX path of (choose file) 

end tell 

display dialog "Are you sure this is the program that you have selected?" 

buttons {"Yes", "No"} 

if the button returned is "No" then 

end repeat 

else 

답변

-1

비록 이것이 나의 죽음으로 이어질지라도 나는 대답 할 것이다. 이 연구 :

set correctChoice to false 

repeat until correctChoice is true -- "is true" is actually unnecessary 

    --I took this next line out because it's unnecessary - you can put this text in the prompt of the choose file, below 
    -- display dialog "Select the program" 

    -- this doesn't need to be (and shouldn't be) in a Finder tell block, so I took that out, too: 
    set filePath to POSIX path of (choose file with prompt "Select the program") 
    set myQuery to display dialog "Are you sure this is the program that you have selected?" buttons {"Yes", "No"} 

    if the button returned of myQuery is "No" then 
     --there is no repeat loop! Where do you want it? I assume you want the repeat outside of this process 
     --end repeat 
    else 
     set correctChoice to true 
    end if 
end repeat 
--maybe do other stuff 

일을 당신이 부울 변수가 true로 설정되어있을 때, 정지 반복 루프, 내부 전체를 넣는 방법을 시도했던 가정 것. if/then은 부울 값의 원래 false 값을 유지하거나 true로 설정하므로 반복 루프를 벗어날 수 있습니다. "해결 방법"은 언어의 제한이나 버그 내에서 작업해야하는 용어입니다. 해결 방법이 필요하지 않습니다. 코드를 올바르게 작성해야합니다. 간단한 (!!)을 시작하고 코드가 당신이해야한다고 생각하는 것을하기 전에 다양한 블록이 어떻게 작동 하는지를 배웁니다.

+0

도움 주셔서 감사합니다. 나는 지금 모든 코드가 작동하고 있으며 내가 잘못한 것을 완전히 이해하고있다. 그것을 지적 주셔서 감사합니다! :) – user7439349

+0

반갑습니다. http://stackoverflow.com/help/someone-answers에서 : "답변을 승인 된 것으로 표시하려면 답변 옆의 체크 표시를 클릭하여 회색으로 표시된 것을 채우기로 전환하십시오." – CRGreen

관련 문제