dim TmpStr as string Open c:\aa.txt For Input As #1 '打开文本文件 Do While Not EOF(1) Line Input #1, TmpStr '读取一行的内容 msgbox TmpStr Loop Close #1
太多了Public Sub File_ReadAll(sFile As String) '将txt文本全部读入 Dim fs, f, s Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile(sFile, 1) s = f.readall f.Close: Set f = Nothing: Set fs = Nothing Debug.Print s End SubPublic Sub File_ReadLine(sFile As String) ’一行一行读入文本,对单行进行处理 Dim fs, f, s Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sFile, 1) Do s = f.readLine '处理过程代码 ' ' Loop Until f.AtEndOfStream f.Close: Set f = Nothing: Set fs = Nothing End Sub
Option Explicit Dim strFile As String Dim strMemo As String Dim intFileNum As Integer '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% '过程功能: '功能描述:Input方式读入文件 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Private Sub btnInput_Click() On Error GoTo errSub strMemo = "" intFileNum = FreeFile(0) Open strFile For Input As #intFileNum Do While Not EOF(intFileNum) Line Input #intFileNum, strMemo txtMemo.Text = txtMemo.Text & strMemo & vbCrLf Loop Close #intFileNum Exit Sub errSub:End SubPrivate Sub Form_Load() strFile = App.Path & "\111.txt"
Open c:\aa.txt For Input As #1 '打开文本文件
Do While Not EOF(1)
Line Input #1, TmpStr '读取一行的内容
msgbox TmpStr
Loop
Close #1
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sFile, 1)
s = f.readall
f.Close: Set f = Nothing: Set fs = Nothing
Debug.Print s
End SubPublic Sub File_ReadLine(sFile As String) ’一行一行读入文本,对单行进行处理
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(sFile, 1)
Do
s = f.readLine
'处理过程代码
'
'
Loop Until f.AtEndOfStream
f.Close: Set f = Nothing: Set fs = Nothing
End Sub
Option Explicit
Dim strFile As String
Dim strMemo As String
Dim intFileNum As Integer
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'过程功能:
'功能描述:Input方式读入文件
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Private Sub btnInput_Click()
On Error GoTo errSub
strMemo = ""
intFileNum = FreeFile(0)
Open strFile For Input As #intFileNum
Do While Not EOF(intFileNum)
Line Input #intFileNum, strMemo
txtMemo.Text = txtMemo.Text & strMemo & vbCrLf
Loop
Close #intFileNum
Exit Sub
errSub:End SubPrivate Sub Form_Load()
strFile = App.Path & "\111.txt"
End Sub