读书人

vb读取txt文件不全的有关问题

发布时间: 2012-02-12 17:16:33 作者: rapoo

vb读取txt文件不全的问题
我用vb读取外部的txt文件,读出来后发现读不全,请问怎么办?

'**********************************************************
'OpenTxt
'用于打开文本文件
'FileName 为要打开的文件路径名称
'返回文本内容
'**********************************************************

Public Function OpenTxt(ByVal FileName As String) As String

'打开txt文本
Dim s As String
Dim sText As String
Dim iFNum As Integer

If Dir(FileName) <> " " Then
iFNum = FreeFile
Open FileName For Input As #iFNum
While Not EOF(iFNum)
Line Input #iFNum, s
If sText = " " Then
sText = s
Else
sText = sText & Chr(13) & Chr(10) & s
End If
Wend
Close #iFNum
End If
OpenTxt = sText
End Function

这是我写的读取函数

[解决办法]
我写一个你试一试,也许对你有所帮助:
Private Sub Command5_Click() '读取让所有写入的内容分段显示了。
Dim rname As String
Dim number As Integer
Dim n As Integer
Text1.Text = " "
Dim s As String
Dim cs As String
rname = App.Path + "\*.txt "
Open rname For Input As #1

Do While Not EOF(1)
s = s + Input(1, #1)
Loop
Text1 = s
MsgBox "读取所有写入的数据,按照写入顺序分段显示,成功! ", vbInformation, "提示 "
Close #1
End Sub
[解决办法]
Public Function OpenTxt(ByVal FileName As String) As String
If Dir(FileName) <> " " Then
Open FileName For Input As #1
OpenTxt = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
End If
End Function

读书人网 >VB

热点推荐