如何用VB将txt文件中的数据取出放入一个数组

11,12,13,14,15,16,17,18,192,3,4,6,7,8,9,0,01,2,3,4,5,6,7,8,921,22,23,45,67,89,671,2,4... 11,12,13,14,15,16,17,18,19
2,3,4,6,7,8,9,0,0
1,2,3,4,5,6,7,8,9
21,22,23,45,67,89,67
1,2,45,67,8,90,67,89

将上述txt文件中的数据取出每行1,3,5,7位置的数,(如:第一行为11,13,15,17,第二行为2,4,7,9)将取出的所有数据放到一个数组中(注意:要把重复的数据去掉,只保留一个),在将这个数组与0到100这个数组比较,找出前一个数组中在0到100范围内没有的数,并将其显示出来

能给出代码,小弟感激不尽
Private Sub Command1_Click()

Dim i As String
Dim k() As String
Open "d:\111.txt" For Input As #1

Do While Not EOF(1)
Line Input #1, i
k = Split(i, ",")
Text1.Text = k(0) & "," & k(2) & "," & k(4) & "," & k(6)
Loop
Close #1
End Sub

这样只能把单独一行的数值取出来,怎样把所有行的数据放到一个数组里呢
展开
 我来答
Yuqi_Tan

2009-07-24 · TA获得超过8.9万个赞
知道大有可为答主
回答量:9918
采纳率:93%
帮助的人:3466万
展开全部
Private Sub Form_Load()
Dim B As String, I As Integer, J As Integer, X As Integer, K(100) As Boolean
Dim B1 As String, Uz() As Integer
Form1.AutoRedraw = True
For I = 0 To 100
K(I) = False
Next
Open "f:\a.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, B
Print B
J = 0
X = 0
Print "提取:";
Do While InStr(B, ",")
J = J + 1
B1 = Left(B, InStr(B, ","))
B = Right(B, Len(B) - InStr(B, ","))
If J Mod 2 = 1 And X < 4 Then
I = Val(B1)
X = X + 1
Print I;
K(I) = True
End If
Loop
If (J + 1) Mod 2 = 1 And X < 4 Then
I = Val(B)
K(I) = True
Print I;
End If
Print
Loop
Close #1
Print: Print "0-100中没有被选出的数字有:"
J = 0
For I = 0 To 100
If K(I) = False Then
Print I;
J = J + 1
If J Mod 10 = 0 Then Print
End If
Next
Print
Print "共有"; J; "个"
ReDim Uz(100 - J)
J = 0
For I = 0 To 100
If K(I) = True Then
Uz(J) = I
J = J + 1
End If
Next
Print: Print "所提取的数组为:"
J = 0
For I = LBound(Uz) To UBound(Uz)
Print Uz(I);
J = J + 1
If J Mod 10 = 0 Then Print
Next
Print
Print "共"; UBound(Uz) + 1; "个数字"
End Sub

已经运行过。
chenxfsoft
2009-07-24 · TA获得超过1380个赞
知道大有可为答主
回答量:2418
采纳率:0%
帮助的人:1842万
展开全部
看了一下,你可以定义一个数组,X(100)
打开文件和读数先不表了,到处都是代码

一行行取数吧,
linestr 行
dim a() as string

set a = splite (linestr,",")

for i = 0 to ubound(a)
x(a(i))=1
next

这样你只要 if x(i) =0 then print i 即可了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式