2017-01-19 11 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は、ブール値の元の偽の値を保持するか、またはtrueに設定します。これにより、繰り返しループを終了することができます。 "回避策"は、言語の制限やバグの中で作業するために必要なものです。回避策は必要ありませんでした。コードを正しく取得する必要があります。シンプルな(!!)を始め、さまざまなブロックがどのように機能するのかを学んでから、コードがあなたがしなければならないと思われることを強制しようとします。

+0

ありがとうございました。私はすべてのコードが今働いており、私が間違ったことを完全に理解することができます。それを指摘してくれてありがとう! :) – user7439349

+0

ようこそ。 http://stackoverflow.com/help/someone-answersから: "回答を受け入れたものとしてマークするには、回答の横にあるチェックマークをクリックして、灰色で塗りつぶしたものから塗りつぶしたものに切り替えます。 – CRGreen

関連する問題