Private Sub Command1_Click() 'read
Dim y() As String, i As Integer
Open "c:\xxx.txt" For Binary As #1
Temp = Space(LOF(1))
Get #1, , Temp
Close #1
y = Split(Temp, vbCrLf)
For i = 0 To UBound(y)
Temp = y(i)
If IsNumeric(Temp) And Len(Temp) = 3 And Temp > "0" Then
num = num + 1
ReDim Preserve x(1 To num)
x(num) = Temp
End If
Next
Close #1
Erase y
End Sub
Private Sub Command2_Click() 'write
Open "c:\newfile.txt" For Binary As #1
Put #1, , Join(x, vbCrLf)
Close #1
End Sub
Private Sub Command1_Click() 'read
num = 0
Open "c:\xxx.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, Temp
If IsNumeric(Temp) And Len(Temp) = 3 And Temp > "0" Then
num = num + 1
ReDim Preserve x(1 To num)
x(num) = Temp
End If
Loop
Close #1
End Sub
Private Sub Command2_Click() 'write
Open "c:\newfile.txt" For Output As #1
Print #1, , Join(x, vbCrLf)
Close #1
End Sub
Do Until txtStream.AtEndOfStream
linestring = txtStream.ReadLine
If IsNumeric(linestring) = True And Len(linestring) = 3 Then
If CInt(linestring) >= 0 And CInt(linestring) <= 999 Then
ReDim Preserve arrResult(1 To i) As String
arrResult(i) = linestring
i = i + 1
End If
End If
Loop
Private Sub Command2_Click()
Dim filestring As String, arrResult() As String, i As Integer, linestring As String
filestring = App.Path & "\a.txt"
Dim ofs As FileSystemObject
Set ofs = New FileSystemObject
Dim txtStream As TextStream
Set txtStream = ofs.OpenTextFile(filestring) '打开文件
i = 1
Do Until txtStream.AtEndOfStream '按行读出
linestring = txtStream.ReadLine
If IsNumeric(linestring) = True And (Asc(linestring) >= Asc("000") And Asc (linestring) <= Asc("999")) Then '判断条件
ReDim Preserve arrResult(1 To i) As String '扩大数组
arrResult(i) = linestring '写入数组
i = i + 1
End If
Loop
txtStream.Close ‘关闭流
Set ofs = Nothing ‘关闭对象
Exit Sub
Dim Temp as string,arrResult() as string,i%
i=1
open "文件路径及名称" for input As #1
Line Input #1, Temp
if Temp>="000" And Temp<="999" then
redim Preserve arrResult(i)
i=i+1
End if
Close #1
Dim Temp as string,arrResult() as string,i%
i=1
open "文件路径及名称" for input As #1
Line Input #1, Temp
if Temp<"000" And Temp>"999" then
redim Preserve arrResult(i)
i=i+1
End if
Close #1