VB怎样在text1中显示D盘记事本文件中的内容?谢谢

对不起,FSO怎么用?... 对不起,FSO怎么用? 展开
 我来答
烂掉の萝卜49d6
2007-04-03 · TA获得超过679个赞
知道小有建树答主
回答量:1233
采纳率:100%
帮助的人:949万
展开全部
Const OFS_MAXPATHNAME = 128
Const OF_CREATE = &H1000
Const OF_READ = &H0
Const OF_WRITE = &H1
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Type OVERLAPPED
Internal As Long
InternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type

Private Sub Form_Load()
Dim OF As OFSTRUCT
Dim hFile As Long
Dim flen As Long
Dim hfilename As String
Dim lnglong As Long
Dim buff() As Byte
Dim i As Long
Dim realnum As Long

If Dir("d:\data.txt") <> "" Then
hfilename = "d:\data.txt"
hFile = OpenFile(hfilename, OF, OF_READ)
flen = GetFileSize(hFile, lnglong)
ReDim buff(flen - 1)
i = ReadFile(hFile, buff(0), flen, realnum, ByVal 0&)
CloseHandle hFile
Dim s As String
s = StrConv(buff, vbUnicode)
Text1.Text = s
Else:
Text1.ForeColor = RGB(255, 0, 0)
Text1.Text = "文件不存在!"
End If

End Sub

这个可以读取任何TXT文件(不能是空白的文件)
百度网友2ca1c0f24
2007-04-03 · TA获得超过2036个赞
知道大有可为答主
回答量:4364
采纳率:0%
帮助的人:3427万
展开全部
用FSO对象读取,然后:
TEXT1.TEXT=读取变量
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式