通过vb 6.0写入文本文件 [英] write in text file thru vb 6.0

查看:184
本文介绍了通过vb 6.0写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的要求是通过vb从文本文件中读取数据。然后计算数据并将结果写入数据已通过vb 6.0重新检索的同一文本文件中。如何在vb 6.0中实现命名空间


i已经使用
获取文本文件

Dim sfil As String

Dim dd

Dim schunk As String

Dim nSourceFile As Integer,sText As String

sfil =" E:\ proposed.txt" ;

nSourceFile = FreeFile


打开sfil输入为#nSourceFile

请勿做EOF(1)

线路输入#1,schunk


然后我完成了计算。现在我想要2将结果写在同一个文本文件中。


任何人都可以帮我解决这个问题。


问候

vivek

解决方案

如果你想为多个记录执行此操作,那么我不认为纯文本文件会起作用。你可能不得不使用随机访问。或二进制模式或二进制模式。文本文件。也就是说,允许您在特定点读/写。


查看Open语句中的二进制和随机选项。我准备离开工作了,所以一段时间不和你在一起......


如果文件中只有一条记录,那么最简单的可能是只需要关闭它然后再打开它再使用Print#来写结果。


hi


你不能使用print只是因为你在输入模式。

一旦你关闭你的文本文件并打开它再次在输出模式打开它,你将丢失所有信息。

所以,建议你在APPEND模式下打开

并使用Print#将数据放在现有数据的末尾。


有一个类似的问题...


>因此,建议您在APPEND模式下打开

>并使用Print#将数据放在现有数据的末尾。 />

但是如何编辑文件呢?你怎么能在文本文件的中间添加数据?


假设您有一个包含大量文本的文本文件。在该文本的某处有一个单词,比如说十月,你想在那之后加几行。当然可以删除单词october之后的所有文本,并将其存储在某处,然后再添加要添加的行,最后再将存储的文本附加到文件的末尾。但这不是一个好的解决方案。特别是对于大文件。


我在这篇文章中读到了关于以二进制模式打开文件或使用随机访问模式的内容。但是你不能在这些模式下编辑文本文件,对吗?如果您希望以后能够在texteditor中打开它,那就不是了。那你怎么解决这个问题呢?


这个迁移是一个新手问题,所以请跟我讨好。 :)

hi
my requirement is read the data from the text file through vb. then calculate the data and write the result on the same text file where the data has retrived thru vb 6.0. how 2 implement the namespace in vb 6.0

i had read the text file by using

Dim sfil As String
Dim dd
Dim schunk As String
Dim nSourceFile As Integer, sText As String
sfil = "E:\proposed.txt"
nSourceFile = FreeFile

Open sfil For Input As #nSourceFile
Do While Not EOF(1)
Line Input #1, schunk


then i had done the calculation . now i want 2 write the result in the same text file.

can anyone help me regarding this issue.

regards
vivek

解决方案

If you want to do this for more than one record, then I don''t think a plain text file will work. You might have to go with a "random access" or "binary mode" text file. That is, one which allows you to read/write at specific points.

Look into the Binary and Random options on the Open statement. I''m about to leave work, so won''t be with you for a while...

If there is only one record in the file, then the simplest thing might be just to Close it then Open it again before using Print # to write the result.


hi

you can''t use print just like that because your in the input-mode.
once you closed your textfile and open this open it again in output-mode, you will lose all information.
so, suggest you open in APPEND-mode
and use Print # to place your data at the end of the existing data.


have a simular problem...

>so, suggest you open in APPEND-mode
>and use Print # to place your data at the end of the existing data.

But how do you edit a file. How can you for example add data in the midle of a textfile?

Say you have a textfile with lots and lots of text. Somewhere in that text there is a word, say "october", and you want to ad a few lines right after that. One could of course remove all text after the word "october", and store it somewhere, Than apend the lines you want to add, and finally append the stored text at the end of the file again. But that isn''t a nice solution. Especially for large files.

I read somthing in this tread about opening the file in binary mode or use random access-mode. But you cant edit a textfile in these modes, can you? Not if you want to be able to open it in a texteditor later. So how do you solve this?

This migth be a newbie question, so have patiance with me. :)


这篇关于通过vb 6.0写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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