用vb编写一个程序,对txt文档中的数据进行查找并输出
txt文档内容为:多行六列的两位数,每行的元素之间用空格分隔要求实现:输入四个两位数后,进行查找,若每行中出现这个四个数则输出...
txt文档内容为:多行六列的两位数,每行的元素之间用空格分隔要求实现:输入四个两位数后,进行查找,若每行中出现这个四个数则输出
展开
1个回答
2013-12-11
展开全部
'假设你的源文件都是合法的,而且每个数都为2位,否则稍微复杂点,这里只做包含判断也就是无序判断,,未作错误处理。
Option Explicit
Private Sub Command1_Click()
Dim s, n, arr(4) As String, i As Integer, j As Integer
s = "c:\123.txt"'源文件位置
If Dir(s) <> "" Then '是否有文件存在
Open s For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
Else
MsgBox "未找到文件:" & s
End If
For i = 0 To 3
n = InputBox("输入4个二位数字,第" & i + 1 & "个:")
If IsNumeric(n) Then
If Val(n) > 9 And Val(n) < 100 Then
arr(i) = n
Else
i = i - 1 '数字但不符合要求
End If
Else
i = i - 1 '非数字
End If
Next
For i = 0 To UBound(s)
For j = 0 To 3
If InStr(s(i), arr(j)) = 0 Then Exit For
Next
If j = 4 Then Print "行数:" & (i + 1) & " 数字:" & Join(arr, ",") '正常退出说明4个数都包含
Next
End Sub
Option Explicit
Private Sub Command1_Click()
Dim s, n, arr(4) As String, i As Integer, j As Integer
s = "c:\123.txt"'源文件位置
If Dir(s) <> "" Then '是否有文件存在
Open s For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
Else
MsgBox "未找到文件:" & s
End If
For i = 0 To 3
n = InputBox("输入4个二位数字,第" & i + 1 & "个:")
If IsNumeric(n) Then
If Val(n) > 9 And Val(n) < 100 Then
arr(i) = n
Else
i = i - 1 '数字但不符合要求
End If
Else
i = i - 1 '非数字
End If
Next
For i = 0 To UBound(s)
For j = 0 To 3
If InStr(s(i), arr(j)) = 0 Then Exit For
Next
If j = 4 Then Print "行数:" & (i + 1) & " 数字:" & Join(arr, ",") '正常退出说明4个数都包含
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询