0
다음 코드가 있습니다. - 시작하기 전에 서브 루틴에있는 일부 변수를 미리 설정/초기화하고 싶습니다. (특히, 제어 파일을 읽고 시작 폴더 검색 경로와 같은 일부 변수를 미리로드합니다.) 어떻게해야합니까?vb.net main은 개인 변수를 설정할 수 없습니다.
공공 Form1 클래스
<STAThread()> _
Shared Sub Main()
Dim mainWindow As Form1 = New Form1()
MessageBox.Show("Hello! I'm exectuing!")
' This next line generates an error.
' I don't know how to set this variable in Main.
' How do I set up variables, perhaps from a control file ?
openFileDialog1.InitialDirectory = "c:\mypath"
Application.Run(mainWindow)
End Sub
Private Sub FindButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles FindButton.Click
' Displays an OpenFileDialog so the user can select a Cursor.
Dim openFileDialog1 As New OpenFileDialog()
' Filter by All Files
openFileDialog1.Filter = "All Files|*.*"
openFileDialog1.Title = "Process a File"
If openFileDialog1.ShowDialog() = DialogResult.OK Then
If openFileDialog1.CheckPathExists Then
If openFileDialog1.CheckFileExists Then
' do stuff with the file here
Else
StatusLabel.Text = "Path does not exist"
End If
Else
StatusLabel.Text = "openFileDialog1.ShowDialog error"
End If
End Sub
최종 클래스