如何在TXT文件中读取数据并存入到VB数组中?
1个回答
2018-01-03 · 知道合伙人教育行家
关注
展开全部
如果TXT文件是单行的话
Open "c:\1.txt" For Binary As #1
Text1.Text = Input(lof(1), 1)
Close #1
Dim a
a = Split(Text1.Text)
如果是多行要加循环
Option Explicit
Dim a$, n%, k%, c$(), d%
Private Sub Form_Click()
n = 0
Open App.Path & "\temp.txt" For Input As #1
Do Until EOF(1)
n = n + 1
Line Input #1, a
ReDim c(n)
d = Len(a)
k = InStr(1, a, "=")
c(n) = Right(a, (d - k + 1))
Print "c(" & n & ")=" & c(n)
Loop
Close #1
End Sub
Open "c:\1.txt" For Binary As #1
Text1.Text = Input(lof(1), 1)
Close #1
Dim a
a = Split(Text1.Text)
如果是多行要加循环
Option Explicit
Dim a$, n%, k%, c$(), d%
Private Sub Form_Click()
n = 0
Open App.Path & "\temp.txt" For Input As #1
Do Until EOF(1)
n = n + 1
Line Input #1, a
ReDim c(n)
d = Len(a)
k = InStr(1, a, "=")
c(n) = Right(a, (d - k + 1))
Print "c(" & n & ")=" & c(n)
Loop
Close #1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询