如何将文本文件中的文本读入VB字符串变量中?

jimqiu 2000-08-29 08:45:00
各位高手:
我想编一个程序,需要将文本文件中的文本自动转入VB的字符串变量中,并自动生成换行符等。请大家指教,不胜感激!
小明 8/29
...全文
418 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Areslee 2000-08-29
  • 打赏
  • 举报
回复
使用文件操作就行了,
0xFFCD 2000-08-29
  • 打赏
  • 举报
回复
GetText 方法示例
本示例使用 GetText 方法从 Clipboard 对象中复制一个文字串至一字符串变量。要检验此示例,可将本例代码粘贴到一个带有一名为 Text1 的 TextBox 控件的窗体的声明部分,然后按 F5 键并单击该窗体。

Private Sub Form_Click ()
Dim I, Msg, Temp ' 声明变量。
On Error Resume Next ' 设置错误处理。
Msg = "Type anything you like into the text box below."
Text1.Text = InputBox(Msg) ' 取得用户正文。
Msg = "Choose OK to copy the contents of the text box "
Msg = Msg & "to the Clipboard."
MsgBox Msg ' 显示信息。
Clipboard.Clear ' 清除剪贴板。
Clipboard.SetText Text1.Text ' 将正文放置在剪贴板上。
If Clipboard.GetFormat(vbCFText) Then
Text1.Text = "" ' 清除该正文框。
Msg = "The text is now on the Clipboard. Choose OK "
Msg = Msg & "to copy the text from the Clipboard back "
Msg = Msg & "to the text box."
MsgBox Msg ' 显示信息。
Temp = Clipboard.GetText(vbCFText) ' 取得剪贴板正文。
For I = Len(Temp) To 1 Step -1 ' 使该正文反向。
Text1.Text = Text1.Text & Mid(Temp, I, 1)
Next I
Else
Msg = "There is no text on the Clipboard."
MsgBox Msg ' 显示错误信息。
End If
End Sub

huntout 2000-08-29
  • 打赏
  • 举报
回复
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
Dim f
Set f = fs.OpenTextFile("c:\testfile.txt", ForReading)
Dim str
str = f.ReadAll
f.Close

7,763

社区成员

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

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