关闭文件和表单 [英] Closing a file and the form

查看:70
本文介绍了关闭文件和表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有 -


我需要更多的帮助。我不太清楚为什么我的文本文件或表格不是
关闭。


短版本 - 此程序将数据输入文本框,用户点击

保存按钮,另存为弹出对话框,用户选择要保存的文件,

data *应该*保存到文件,文件关闭,表单关闭。


到目前为止我写的方式,数据*确实*保存到文件,但是,

我必须先关闭文件,然后重新打开它以查看更改。我已经用b / b
了解一下表格和文件后关闭

用户从另存为对话框中选择文件并单击确定 。


前几天我从你们中的一些人那里得到了帮助,并且希望能够朝着正确的方向再次踢一下......我不是......我不是还不熟悉.NET语法。


这里是我正在玩的代码片段......

选择Case sFileExtension。 ToUpper

Case" .TXT"


Shell(notepad.exe"& sFileName,AppWinStyle.MaximizedFocus)


FileOpen(f,sFileName,OpenMode.Append)


PrintLine(f,sInfo)


''FileClose( f)''不起作用


''Form1.ActiveForm.Hide()''不起作用

解决方案

我还应该提到我尝试使用StreamWriter作为我们ll with

没有运气。


-Kelly


" Kelly" <柯********** @ amerock.com>在留言中写道

news:u7 ************** @ TK2MSFTNGP11.phx.gbl ...

嘿所有 -

我还需要一些帮助。我不太清楚为什么我的文本文件或表单
没有关闭。

短版本 - 此程序将数据输入文本框,用户
点击保存按钮,另存为对话框弹出打开,用户选择要保存的文件,
数据*应该*保存到文件,文件关闭,格式关闭。

我写的方式如此远,数据*确实*保存到文件,
然而,我必须先关闭文件,然后重新打开它以查看更改。
在用户从另存为对话框中选择文件并单击确定后,我已经使用了一些代码来获取表单和文件以关闭

前几天我从你们中的一些人那里得到了帮助,希望能够朝着正确的方向再次开始......我对.NET语法还不太熟悉。
这里是我正在玩的代码片段......

选择Case sFileExtension.ToUpper
案例.TXT

Shell (" notepad.exe"& sFileName,AppWinStyle.MaximizedFocus)

FileOpen(f,sFileName,OpenMode.Append)

PrintLine(f,sInfo)

''FileClose(f)''不起作用

''Form1.ActiveForm.Hide()''不起作用


*" Kelly" <柯********** @ amerock.com> scripsit:

我需要更多的帮助。我不太清楚为什么我的文本文件或表单没有关闭。

短版本 - 此程序将数据输入文本框,用户点击
保存按钮,另存为对话框弹出打开,用户选择要保存的文件,
数据*应该*保存到文件,文件关闭,格式关闭。

我写的方式如此到目前为止,数据*确实*保存到文件中,然后,我必须先关闭文件,然后重新打开它才能看到更改。




那是因为文件访问是缓冲的。因此,无法保证

数据会立即写入文件。如果连续调用将数据写入<的方法,则会保证它将被写入保证

,并保证它将以

正确的顺序写入br />
文件。


如果您使用的是''System.IO.StreamWriter'',您可以将其称为''Flush''

方法使缓冲数据持久。


-

MS Herfried K. Wagner

MVP< URL :http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>


Kelly,


看一下streamreader / writer类,并告诉我们这段代码中有什么shell

notepad。

http://msdn.microsoft.com/library/de...ClassTopic.asp

http://msdn.microsoft.com/library/de...classtopic .asp


我希望这对此有帮助吗?


Cor


Hey all -

I need a little more help. I don''t quite know why my text file or form isn''t
closing.

Short version - this program takes data entered into a textbox, user clicks
Save button, Save As dialog box pops open, user selects file to save to,
data *should* save to the file, file close, form close.

The way I have it written so far, the data *does* save to the file, however,
I have to first close the file and then re-open it to see the changes. I''ve
been playing with the code a little to get the form and file to close after
the user selects the file from the Save As dialog box and clicks OK.

I got help the other day from a few of you and was hoping for another kick
in the right direction...I''m not too familiar with the .NET syntax yet.

Here''s the snippet of code I''m playing with...
Select Case sFileExtension.ToUpper
Case ".TXT"

Shell("notepad.exe " & sFileName, AppWinStyle.MaximizedFocus)

FileOpen(f, sFileName, OpenMode.Append)

PrintLine(f, sInfo)

''FileClose(f) '' doesn''t work

''Form1.ActiveForm.Hide() '' doesn''t work

解决方案

I should also mention that I tried using StreamWriter for this as well with
no luck.

-Kelly

"Kelly" <ke**********@amerock.com> wrote in message
news:u7**************@TK2MSFTNGP11.phx.gbl...

Hey all -

I need a little more help. I don''t quite know why my text file or form isn''t closing.

Short version - this program takes data entered into a textbox, user clicks Save button, Save As dialog box pops open, user selects file to save to,
data *should* save to the file, file close, form close.

The way I have it written so far, the data *does* save to the file, however, I have to first close the file and then re-open it to see the changes. I''ve been playing with the code a little to get the form and file to close after the user selects the file from the Save As dialog box and clicks OK.

I got help the other day from a few of you and was hoping for another kick
in the right direction...I''m not too familiar with the .NET syntax yet.

Here''s the snippet of code I''m playing with...
Select Case sFileExtension.ToUpper
Case ".TXT"

Shell("notepad.exe " & sFileName, AppWinStyle.MaximizedFocus)

FileOpen(f, sFileName, OpenMode.Append)

PrintLine(f, sInfo)

''FileClose(f) '' doesn''t work

''Form1.ActiveForm.Hide() '' doesn''t work



* "Kelly" <ke**********@amerock.com> scripsit:

I need a little more help. I don''t quite know why my text file or form isn''t
closing.

Short version - this program takes data entered into a textbox, user clicks
Save button, Save As dialog box pops open, user selects file to save to,
data *should* save to the file, file close, form close.

The way I have it written so far, the data *does* save to the file, however,
I have to first close the file and then re-open it to see the changes.



That''s because file access is buffered. So, there is no guarantee that
the data will be written to the file immediately. There is a guarantee
that it will be written, and a guarantee that it will be written in the
right order if there are successive calls to methods that write data to
the file.

If you are using ''System.IO.StreamWriter'', you can call its ''Flush''
method to make the buffered data persistent.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Kelly,

Have a look at the streamreader/writer class and tell us what that shell
notepad does in this code.

http://msdn.microsoft.com/library/de...ClassTopic.asp

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps anyway?

Cor


这篇关于关闭文件和表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆