使用VB 6.0中的文件 [英] Working with files in VB 6.0

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

问题描述

我有一个RTF文件,就像一个报告,有一些文本和一些变量名称与表字段名称相同。我希望我的程序逐个字符地读取RTF文件,然后每当遇到字段名称时,它应该用表字段值替换它。每当它遇到一个空格或任何标签或任何特殊字符时,它应该只写,即格式应该保持与仅替换值代替字段名称之前的格式相同。你能为我提供代码,我迫切需要它。谢谢你

I''ve a RTF file which is like a report having some text and some variable names same as the table field name. I want my program to read the RTF file character by character, then whenever it encounters a field name , it should replace it with the table field value. And whenever it encounters a space or any tag or any special character , it should write that only i.e. the format should remain the same as before only the values to be substituted in place of field names. Can you provide me the code , i need it urgently. Thanking You

推荐答案

你可以尝试使用ReadLine方法并将结果存储在缓冲区(或字符串)中,

在这里你找到如何使用ReadLine方法:

''---------------------------------- -------------------------------------------------- ---

Dim f,fs

Dim buff As String

Dim ForReading

ForReading = 1

设置fs = CreateObject(" Scripting.FileSystemObject")

设置f = fs.OpenTextFile(" c:\Documents and Settings \ my folder \ testfile。 txt",ForReading,TristateFalse)


buff = f.Readline


f.Close

MsgBox buff' 'view buffer string

''------------------------------------ -------------------------------------------------- -

当然这不是你问题的完整代码,但它给你一个起点。

注意:

我认为它'不可能一次读取和写入同一个文件需要使用输出文件


You can try to use ReadLine method and to store the result in a buffer (or string),
Here you find how to use ReadLine method:
''---------------------------------------------------------------------------------------
Dim f, fs
Dim buff As String
Dim ForReading
ForReading = 1
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\Documents and Settings\my folder\testfile.txt",ForReading, TristateFalse)

buff = f.Readline

f.Close
MsgBox buff '' view buffer string
''---------------------------------------------------------------------------------------
Of course this is not the complete code for your problem but it gives you a starting point.
Note:
I think it''s not possible read and write the same file at once you need to use an output file




我有一个RTF文件这就像一个报告,其中包含一些文本和一些与表字段名称相同的变量名称。我希望我的程序逐个字符地读取RTF文件,然后每当遇到字段名称时,它应该用表字段值替换它。每当它遇到一个空格或任何标签或任何特殊字符时,它应该只写,即格式应该保持与仅替换值代替字段名称之前的格式相同。你能为我提供代码,我迫切需要它。感谢你
I''ve a RTF file which is like a report having some text and some variable names same as the table field name. I want my program to read the RTF file character by character, then whenever it encounters a field name , it should replace it with the table field value. And whenever it encounters a space or any tag or any special character , it should write that only i.e. the format should remain the same as before only the values to be substituted in place of field names. Can you provide me the code , i need it urgently. Thanking You



我有一个RTF文件,就像一个有一些文字和一些文字的报告变量名与表字段名相同。我希望我的程序逐个字符地读取RTF文件,然后每当遇到字段名称时,它应该用表字段值替换它。每当它遇到一个空格或任何标签或任何特殊字符时,它应该只写,即格式应该保持与仅替换值代替字段名称之前的格式相同。你能为我提供代码,我迫切需要它。谢谢你
I''ve a RTF file which is like a report having some text and some variable names same as the table field name. I want my program to read the RTF file character by character, then whenever it encounters a field name , it should replace it with the table field value. And whenever it encounters a space or any tag or any special character , it should write that only i.e. the format should remain the same as before only the values to be substituted in place of field names. Can you provide me the code , i need it urgently. Thanking You



如果你在表单上放置一个 RichTextBox 控件,它可能会简化一些事情(首先在下添加到你的项目中) P roject | Componen t s )。将文件读入此控件后,您可以处理文本,格式或两者。希望你不必解释所有标签。

It might simplify things if you place a RichTextBox control on your form (add it to your project first, under Project | Components). Once you read the file into this control, you can deal with the text, the formatting or both. And hopefully, you won''t have to interpret all the tags.


hi,

我使用了以下代码。但我不知道如何将文件的内容读成字符串。根据你,我不能一次读取和写入相同的文件,所以我该怎么做。如何将文件内容读入缓冲区,然后将其写入输出文件以生成相同的格式。你能救我吗?谢谢你。


Dim oWordDoc As Word.Document

Dim AppWord As New Word.Application

Dim f,fs As Object

Dim buffer As String

Dim FileName As String

FileName =" C:\ KPN \ Q0000001.RTF"

设置oWordDoc = AppWord.Documents.Open(FileName)

i''ve used the following code. but i don''t know how to read the contents of the file into a string. According to you i can''t read and write the same file at once, so how can i do that. how can i read the file contents into buffer and then write it to an output file to make the same format. Could you help me out. Thanking You.

Dim oWordDoc As Word.Document
Dim AppWord As New Word.Application
Dim f, fs As Object
Dim buffer As String
Dim FileName As String
FileName = "C:\KPN\Q0000001.RTF"
Set oWordDoc = AppWord.Documents.Open(FileName)


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

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