如何把txt文件中的一列数据转成一维数组?
我有一个txt文件,里面是一列数字:123
456
789
请问我如何把它转成一个一维数组?我的代码如下,a是我想得到数组,但是总是不对。
Private Sub cmdopen_Click()
CommonDialog1.Action = 1
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
num = Val(inputdata)
Data = Data + inputdata + vbCrLf
End If
Loop
a = Split(Data)
Close #1
End Sub
[解决办法]
参考:http://blog.csdn.net/zcsor/archive/2007/03/07/1522705.aspx
Private Sub cmdDel_Click()
Dim mArray() As Byte, mFileLen As Long, mStr As String, mTmpStr() As String, mIndex As Long 'FOR循环中用到的变量
Open mPathName For Binary As #1 '将文件读入数组
mFileLen = LOF(1)
ReDim mArray(mFileLen - 1)
Get #1, , mArray()
Close #1
mStr = StrConv(mArray(), vbUnicode) '将数组合成为字符串
mTmpStr() = Split(mStr, vbCrLf) '将字符串分离成字符串数组
End Sub
如果是你的代码,大体上应该修改这些地方:
Private Sub cmdopen_Click()
CommonDialog1.Action = 1
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
num = Val(inputdata)
Data = Data + inputdata + vbCrLf
End If
Loop
a = Split(Data,VBCRLF)
Close #1
End Sub