ファイルの存在をチェックする関数があります (return file.exists(file))。存在しない場合は、中止、再試行、無視のオプションを含むエラー メッセージを表示します。
私の問題は、再試行できないことです。
ファイルが別の関数に存在するかどうかを確認するコードを配置してから、select case ステートメントの再試行ケースからその関数を呼び出してみましたが、それを通り過ぎているようです (存在しないことを既に知っているためですか? )ファイルが存在するかどうかを確認する関数を含む別のクラスを作成してから、呼び出すたびにそのクラスの新しいインスタンスを作成しようとしましたが、役に立ちませんでした。
何か不足していますか?
ユーザーが [再試行] をクリックするたびに、ユーザーが中止または無視を押すまで (または、もちろんファイルが見つかるまで)、アプリケーションが再度チェックし続けるようにしたいと考えています。
再試行を処理する適切な方法は何ですか?
Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If CheckFileExists() Then
'do stuff here
End If
End Sub
Private Function CheckFileExists()
If Not FindFile() Then
Select Case MessageBox.Show("Can't Find File", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error)
Case Windows.Forms.DialogResult.Abort
End
Case Windows.Forms.DialogResult.Retry
Return FindFile()
Case Windows.Forms.DialogResult.Ignore
MessageBox.Show("Proceeding without file present")
'do some other stuff
Return True
Case Else
Return False
End Select
Else
Return True
End If
End Function
Private Function FindFile() As Boolean
Return System.IO.File.Exist(path\file.ext)
End Function
私もそれをクラスに入れてみました:
Private Function FindFile() As Boolean
Dim fc As New FileCheck
If Not fc.fnFileCheck() Then
Return False
Else
Return True
End If
End Function
Public Class FileCheck
Public Function fnFileCheck() As Boolean
Return System.IO.File.Exist(path\file.ext)
End Function
End Class