질문하기 전에 인터넷에서 많은 검색을 수행했지만 내 문제에 대한 답변을 찾지 못했습니다. 버튼이 하나 있고 클래스가 두 개인 Form이 하나 있습니다. Form의 Button을 누르면 디스크에서 file.txt를 선택하는 대화 상자가 열립니다. 만약 Open Button을 누르면 프로그램은 코드에 쓰여진 것을 정확하게 수행합니다. 취소 단추를 누르면 프로그램에서 오류가 발생합니다. System.NullReferenceException : '개체 인스턴스에 대한 개체 참조가 설정되어 있지 않습니다.' 경로는 아무것도 아니었다. (On Class FilePan nomeFilePan = path.Replace ("1319", "panasonic \") + _nomeFile + ".pan")openFileDialog에서 취소 버튼을 누르면 오류가 나타나지 않습니다.
프로그램을 다시 Form으로 보내려면 어떻게해야합니까? 버튼을 눌러 파일을 열거 나 프로그램을 닫으시겠습니까?
Imports System
Public Class Form1
Dim _fileTxt As FileTxt = New FileTxt()
Dim CreaPan As FilePan = New FilePan()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
_fileTxt.SetFileTxt()
CreaPan.SetFilePan(_fileTxt.GetNomeFile(), _fileTxt.GetPath())
End Sub
End Class
Public Class FileTxt
Dim path As String
Dim nomeFile As String
Dim nomeFileTxt As String
Public Sub SetFileTxt()
Dim openFileDialog1 As New OpenFileDialog() With
{
.InitialDirectory = "",
.Filter = "Txt file|*txt",
.FilterIndex = 1,
.RestoreDirectory = True,
.Title = "Seleziona file"
}
If openFileDialog1.ShowDialog() = DialogResult.OK Then
path = IO.Path.GetDirectoryName(openFileDialog1.FileName)
nomeFile = IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName)
nomeFileTxt = IO.Path.GetFileName(openFileDialog1.FileName)
Else
' How can go back the program start (Form1 with the button)???
End If
End Sub
Public Function GetNomeFile() As String
Return nomeFile
End Function
Public Function GetPath() As String
Return path
End Function
End Class
Imports System.IO
Public Class FilePan
Dim path As String
Dim nomeFilePan As String
Public Sub SetFilePan(ByVal _nomeFile As String, ByVal _path As String)
path = _path
nomeFilePan = path.Replace("1319", "panasonic\") + _nomeFile + ".pan"
If File.Exists(nomeFilePan) Then
File.Delete(nomeFilePan)
End If
End Sub
End Class
같은 것을 시도'취소 할 경우 then' 뭔가를하거나 허용되지 않는 취소하지 않으면 당신은 당신의 else 문 – Werdna
@Werdna에'Return'을 넣을 수 있습니다. Else 문장에서 반환 같은 오류 –