跪求高手帮忙!请高手进来解决!一定给分!

lz8064 2004-04-12 10:15:39
我现在有一段代码!

'引用Microsoft Scripting Runtime
'引用Microsoft Script Control 1.0
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim CreateIt
Set CreatIt = fso.CreateTextFile("D:\你好.txt", True)
End Sub

Private Sub Command2_Click()
Dim fso As New FileSystemObject
Kill "D:\你好.txt"
Dim CreateIt
Set CreatIt = fso.CreateTextFile("D:\谢谢,我很好!.txt", True)
End Sub

Private Sub Command3_Click()

Open "D:\谢谢,我很好!.txt" For Output As #1
Print #1, "你呢?"
Close #1

End Sub

Private Sub Command4_Click()
Kill "D:\谢谢,我很好!.txt"
End Sub

我需要在第一步的代码中新建文件《你好.txt》的同时在读取另一个在D:\*.txt中的全部字符!

然后在第三步的代码中替换第一步读取数据的文件《你好.txt》里所有带括号的字符为《你呢!》

那位高手能帮帮我啊!求帮助了!谢谢高手了一定给分啊!

...全文
87 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzp1030 2004-04-12
  • 打赏
  • 举报
回复
我需要在第一步的代码中新建文件《你好.txt》的同时在读取另一个在D:\*.txt中的全部字符到《你好.txt》文件中!
是这个意思吗??
'引用Microsoft Scripting Runtime
'引用Microsoft Script Control 1.0
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim CreateIt
Set CreatIt = fso.CreateTextFile("D:\你好.txt", True)
Open "D:\*.txt" For input As #1
Old_Str_File = StrConv(InputB(LOF(1), #1), vbUnicode)

open "D:\你好.txt" for output as #2
print #2,Old_Str_File

End Sub
lizhong8064 2004-04-12
  • 打赏
  • 举报
回复
dim IsUnicode as boolean '用来判断文本文件是否unicode编码格式
dim txtfiledata() as byte '保存文本文件数据
dim txtfilehead(1) as byte '用来判断文本文件的头两个字符,通过判断头两个字符是否为"&hFF,&hFe"就能知道是否unicode格式了

open "c:\1.txt" for binary as #1
get #1,,txtfilehead
if txtfilehead(0)=&hFF and txtfilehead(1)=&hFe then '判断文件头是否为"&hff,&hfe"
IsUnicode=true
else
IsUnicode=false
end if
close #1

open "c:\1.txt" for binary as #1
if Isunicode=true then
redim txtfiledata(lof(1)-2)
get #1,3,txtfiledata '假如是unicode编码格式,则从文本的第三个字节读起
else
redim txtfiledata(lof(1))
get #1,,txtfiledata
end if
close #1

txtfiledata=StrConv(txtfiledata,vbunicode)

text1.text=txtfiledata
lz8064 2004-04-12
  • 打赏
  • 举报
回复
不乱啊!写的很明白啊!有什么地方不懂呢?
射天狼 2004-04-12
  • 打赏
  • 举报
回复
什么啊,乱!!!
lz8064 2004-04-12
  • 打赏
  • 举报
回复
我现在有一段代码!

'引用Microsoft Scripting Runtime
'引用Microsoft Script Control 1.0
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim CreateIt
Set CreatIt = fso.CreateTextFile("D:\你好.txt", True)
End Sub

Private Sub Command2_Click()
Dim fso As New FileSystemObject
Kill "D:\你好.txt"
Dim CreateIt
Set CreatIt = fso.CreateTextFile("D:\谢谢,我很好!.txt", True)
End Sub

Private Sub Command3_Click()

Open "D:\谢谢,我很好!.txt" For Output As #1
Print #1, "你呢?"
Close #1

End Sub

Private Sub Command4_Click()
Kill "D:\谢谢,我很好!.txt"
End Sub

我需要在第一步的代码中新建文件《你好.txt》的同时在读取另一个在D:\*.txt中的全部字符到《你好.txt》文件中!

然后在第三步的代码中替换第一步读取数据的文件《你好.txt》里所有带括号的字符为《你呢!》

那位高手能帮帮我啊!求帮助了!谢谢高手了一定给分啊!
northwolves 2004-04-12
  • 打赏
  • 举报
回复
'add a textbox and a commandbutton to form1
Private Sub Command1_Click()
MsgBox tihuan(Text1.Text, "(", ")")
End Sub
Function tihuan(ByVal x As String, splitA As String, SPLITB As String) As String
Dim TEMP, I As Long
tihuan = ""
x = Replace(x, SPLITB, splitA)
TEMP = Split(x, splitA)
For I = 1 To UBound(TEMP) Step 2
TEMP(I) = "《你呢!》"
Next
tihuan = Join(TEMP, "")
Set TEMP = Nothing
End Function

Private Sub Form_Load()
Text1 = "(abcd)123(4567)a(bcd)efg(hijk)m"
End Sub

yoki 2004-04-12
  • 打赏
  • 举报
回复
没有明白你的意思,如果替换某字符串直接将文件内容读到一个变量中,然后用replace函数替换后再重新写入原文件即可

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧