VB 数组的详细用法.比如读几行文件内容放到数组.

来源:百度知道 编辑:UC知道 时间:2024/06/25 08:41:51
我要把很几M的文件一次读几行到数组里面去
急急急!!!!!!
如果我要用数组读以下的文件内容(很大不止以下的)假如我想实现用一个数组(i)读一行(GOTO / -150.0922902817, -50.4022098210, -39.7050468450, $
0.0000000000, -0.4587136889, 0.8885841275)然后去掉了"GOTO /"再用一个数组把该行按","再分放到另一个数组a.然后再读下一行的到数组再按","分到数组a/.
然后后一个数减前一个数应该怎么使用数组啊??
GOTO / -150.0922902817, -50.4022098210, -39.7050468450, $
0.0000000000, -0.4587136889, 0.8885841275
GOTO / -150.1445397409, -26.1332602092, -22.0694194183, $
0.0000000000, -0.4587136889, 0.8885841275
GOTO / -150.1470948572, -24.9464538452, -21.2069974678, $
0.0000000000, -0.4782666459, 0.8782146750
GOTO / -150.1414400247, -23.4619706246, -20.0610528995, $
0.0000000000, -0.5118971452, 0.8590467465
GOTO / -150.1496040170, -21.9814262984, -18.8173801827, $
0.0000000000, -0.5407506828, 0.8411829165
GOTO / -150.1712475338, -20.1926600967, -17.1905334346, $
0.0000000000, -0.5719342882, 0.8

Private Sub Form_Click()
Dim strtemp As Variant
Dim strtemp1 As Variant
Dim strAry As Variant

Open "C:\test.txt" For Input As 1
strtemp = Input$(LOF(1), 1)
Close 1
'Open "C:\test.txt" For Binary As 1
' strtemp = Input$(LOF(1), 1)
'Close 1

strtemp = Replace(Replace(strtemp, "GOTO /", ""), " ", "")
strtemp = Split(Replace(strtemp, " ", ""), vbCrLf)

Dim Cou As Long, i As Long, j As Long
Cou = UBound(strtemp)
ReDim strAry(Cou, 0)

For i = 0 To Cou
strtemp1 = Split(strtemp(i), ",")
For j = 0 To UBound(strtemp1)
ReDim Preserve strAry(Cou, j)
strAry(i, j) = strtemp1(j)
Debug.Print "strAry(" & i & ", " & j & ")=" & strAry(i, j)
Next
Erase strtemp1
Next
End Sub

你错了,定义String只要