如何用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
这样只能把单独一行的数值取出来,怎样把所有行的数据放到一个数组里呢 展开
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
这样只能把单独一行的数值取出来,怎样把所有行的数据放到一个数组里呢 展开
2个回答
展开全部
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
已经运行过。
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
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 "共有"; 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 "共"; UBound(Uz) + 1; "个数字"
End Sub
已经运行过。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询