2017-01-19 44 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 /然後或者保持布爾值的原始假值,或者將其設置爲真,從而允許我們離開重複循環。 「解決方法」是一個術語,用於在語言限制或錯誤內工作。你不需要一個解決方法 - 你需要讓你的代碼正確。在嘗試強制代碼執行您認爲應該做的事情之前,先簡單地開始(!!)並學習各種代碼塊是如何工作的。

+0

感謝您的幫助。我現在的代碼都在工作,並且完全理解我做錯了什麼。感謝您指出! :) – user7439349

+0

不客氣。來自http://stackoverflow.com/help/someone-answers:「要將答案標記爲已接受,請單擊答案旁邊的複選標記以將其從灰色變爲填充。」 – CRGreen