タイトル : Re^2: FileOpenは使用しないほうがいい? 投稿日 : 2008/04/22(Tue) 09:50 投稿者 : 皐月
花ちゃんさん返信ありがとうございます。 .FlieNameの取得はOKボタンが押されたときのみ、ユーザーが設定したファイル名を保存できるようになっているので、If .ShowDialog() = Windows.Forms.DialogResult.OK Thenを追加して、.FileNameが取得できたときのみ、FileOpenの処理ができるように変更しました。 Private Sub Menu_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_Save.Click Dim Freenumber As String With SaveFileDialog1 Try ChDrive(My.Application.Info.DirectoryPath) ChDir(My.Application.Info.DirectoryPath & "\Setdata") If .ShowDialog() = Windows.Forms.DialogResult.OK Then ←これを追加しました Freenumber = CStr(FreeFile()) FileOpen(CInt(Freenumber), .FileName, OpenMode.Output) 'データ保存 ・ ・ ・ FileClose(CInt(Freenumber)) Exit Sub end if Catch ex As System.IO.IOException ChDrive(My.Application.Info.DirectoryPath) ChDir(My.Application.Info.DirectoryPath & "\Setdata") End Try End With End Sub |