- 帖子
- 61
- 积分
- 70
- 技术
- 1
- 捐助
- 0
- 注册时间
- 2015-8-9
|
[技术讨论] [已解决]求助,下面的vb代码为什么检索的部分只能检索第一个后面都检索不出???
本帖最后由 707093864 于 2015-12-30 20:47 编辑
Dim c() As Variant, d() As Variant, m As Integer, n As Integer
Private Sub enter_Click()
Dim s As Integer, a(), b()
m = Val(InputBox("请输入录入的数据数量", "输入"))
ReDim a(m), b(m)
Open App.Path & "\data1.txt" For Append As #1
Open App.Path & "\data2.txt" For Append As #2
For i = 1 To m
a(i) = InputBox("请输入名称", "输入")
Print #1, a(i)
b(i) = InputBox("请输入金额", "输入")
Print #2, b(i)
Next i
Close #1
Close #2
MsgBox "数据录入完成"
End Sub
Private Sub read_Click()
Open App.Path & "\data1.txt" For Input As #1
n = 0
Do While Not EOF(1)
Line Input #1, Data1
n = n + 1
Loop
Close #1
Open App.Path & "\data1.txt" For Input As #1
ReDim c(n), d(n)
If Not EOF(1) Then
For i = 1 To n
Input #1, c(i)
Next i
End If
Open App.Path & "\data2.txt" For Input As #2
If Not EOF(1) Then
For i = 1 To n
Input #2, d(i)
Next i
End If
Close #1
Close #2
MsgBox "数据读取完成,一共" & n & "条数据"
Text1.Enabled = True
Text1.SetFocus
End Sub
Private Sub Command2_Click()
If Text1.Text = "" Then
MsgBox "请输入要查找的内容"
Text1.SetFocus
Else
For i = 1 To n
If Text1.Text = c(i) Then
MsgBox "姓名:" & c(i) & vbCrLf & "金额:" & d(i)
Else
MsgBox "未查到此人信息"
Exit For
End If
Next i
End If
End Sub |
|