怎么把一个TextStream的文本内容赋给一个string变量?

muzuiget 2005-07-20 04:42:49
怎么把一个TextStream的文本内容赋给一个string变量?
用FSO对象,比如我读入一个txt文件,,想把txt文件的内容赋给一个string变量,代码应该如何?
...全文
95 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
muzuiget 2005-07-20
  • 打赏
  • 举报
回复
嗯,解决了.感谢
wangtopcool 2005-07-20
  • 打赏
  • 举报
回复
使用fso对象的方法
Function FsoRead(ByVal PFile As String) As String
On Error Resume Next
Dim u As Object
Dim X As TextStream
Set u = CreateObject("scripting.filesystemobject")
Set X = u.OpenTextFile(PFile, ForReading, True)
FsoRead = X.ReadAll
Exit Function
End Function

Private Sub Command1_Click()
Dim ss As String
ss = FsoRead("C:\temp.txt")
End Sub
wangtopcool 2005-07-20
  • 打赏
  • 举报
回复
不用fso对象的方法
Private Sub Command1_Click()
Text1.Text = ReadFile("C:\temp.txt")
End Sub

Function ReadFile(TXTFile As String) As String
Dim fn As Integer
fn = FreeFile
Open TXTFile For Binary Access Read As #fn
ReadFile = Space(FileLen(TXTFile))
Get #fn, , ReadFile
Close #fn
End Function

7,763

社区成员

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

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