| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

问题点数：0 回复次数：3

3456
8764
3374

Dim 数组() As String '定义一个动态数组
Dim i As Integer
Open "C:\Users\Admin\Desktop\1.txt" For Input As 1#   '打开输入文件
Do While Not EOF(1)
ReDim Preserve 数组(i)  '分配数组，保留原来的数据
Line Input #1, 数组(i)  '读入数据
i = i + 1
Loop
For i = 0 To UBound(数组)
Debug.Print 数组(i)
Next

Debug.Print
Debug.Print 数组(0)

Close #1    '关闭文件
End Sub

Dim data As String
Dim buffer As String
Dim str As String
Open "1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, buffer
data = data + buffer + vbCrLf
Loop
'MsgBox data
Close #1
S = Split(data, Chr(13) & Chr(10))  '以回车换行符作为分隔符
For i = 0 To UBound(S)
MsgBox S(i)
Next
End Sub

Dim data As String
Dim buffer As String
Dim str As String
Open "1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, buffer
data = data + buffer + vbCrLf
Loop
'MsgBox data
Close #1
str = Replace(data, Chr(13) & Chr(10), ",") '回车换行符全部替换成逗号
S = Split(str, ",") '以逗号作为分隔符
For i = 0 To UBound(S)
MsgBox S(i)
Next
End Sub

3456
8764
3374

3456
8764
3374

```Sub Test()
Dim s() As String, t(1 To 4) As Long, i&, j&, sum&
Open "d:\1.txt" For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
For i = 0 To UBound(s)
sum = 0
For j = 1 To 4
t(j) = Val(Mid(s(i), j, 1))
sum = sum + t(j)
Next
s(i) = s(i) & "-->" & sum
Next
MsgBox Join(s, vbCrLf)
End Sub
```
• 4
• 1/1页
• 1