0
시작할 때 기본 경로 파일을 선언 할 때 문제가 있습니다.
프로그램을 실행할 때마다 pathFile이 null이라는 것을 의미합니다. 누군가 내 코드에서 무엇을 변경해야하는지 알고 있습니까?OnLoad Sub (Visual Basic)에 문제가 있습니다.
Imports System
Imports System.IO
Imports System.Text
Public Class GlobalVariables
Public Shared pathFile As String
End Class
Public Class Form1
Protected Overridable Sub OnLoad(e As EventArgs)
GlobalVariables.pathFile = My.Computer.FileSystem.SpecialDirectories.Desktop
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
' create or overwrite the file
Dim fs As FileStream = File.Create(GlobalVariables.pathFile)
' add text to file
Dim info As Byte() = New UTF8Encoding(True).GetBytes(rtbText.Text)
fs.Write(info, 0, info.Length)
fs.Close()
End Sub
End Class
미리 감사드립니다.
Private Sub Form_Load(sender As Object, e As System.EventArgs) Handles Me.Load
GlobalVariables.pathFile = My.Computer.FileSystem.SpecialDirectories.Desktop
End Sub
당신은 아마 pathFile
가 선언 된 값을 설정할 수 있습니다 : -
대신 OnLoad
을 무시하려고 노력 Xaaf 코드
경로에 대한 액세스가 거부되었다는 메시지가 나타납니다. 이것은 'Dim fs As FileStream = File.Create (GlobalVariables.pathFile)'입니다. –
@XaafCode 글쎄, 그건 당신의 질문과 관련이 없지만 ['File.Create'] (https://msdn.microsoft. "지정한 경로의 파일을 만들거나 덮어 씁니다."지정한 경로는 파일이 아니며 이미 존재하는 바탕 화면 디렉터리입니다. com/ko-kor/library/d62kzs03 (v = vs.110) .aspx) 액세스가 거부 된 것은 아마도 좋은 일입니다! :-) – Mark
오, 고마워요! 그것에 대해 정말로 생각하고 있지 않았습니다! :디 –