有关VB。inputbox函数。的查询问题
我现在用文档形式写出了一个顺序文件的读取的工程。其中内容有职工姓名,部门,电话等。我现在需要做一个信息检索。信息检索的部分是按名字查找和按部门查找这2个功能。。查找是用I...
我现在用文档形式写出了一个顺序文件的读取的工程。其中内容有职工姓名,部门,电话等。我现在需要做一个信息检索。信息检索的部分是按名字查找和按部门查找这2个功能。。查找是用INPUTBOX输入职工的姓名或者部门。 显示出职工的信息,请问怎么才能用VB做出查询啊?纠结俩三天了
Private Sub Command1_Click()
Dim n As String
Static i As Integer
Public strname As String
n = InputBox("请输入员工的姓名")
i = 1
If Mid(strname, 1, Len(n)) = n Then Me.Hide
Form2.Show
Form2.Print strname
Print strname;
Else
i = i + 1
Open "C:\Users\sony\Desktop\vb\新建文本文档.txt" For Input As #i
While Not EOF(1)
Line Input #i , strname
Wend
Close #1
End If
End Sub
代码2
Private Sub Command1_Click()
Dim strname As String
Open "d:\he.txt" For Input As #1
While Not EOF(1)
Line Input #1, strname
Me.Hide
Form2.Show
Form2.Print strname
Wend
Close #1
End Sub 展开
Private Sub Command1_Click()
Dim n As String
Static i As Integer
Public strname As String
n = InputBox("请输入员工的姓名")
i = 1
If Mid(strname, 1, Len(n)) = n Then Me.Hide
Form2.Show
Form2.Print strname
Print strname;
Else
i = i + 1
Open "C:\Users\sony\Desktop\vb\新建文本文档.txt" For Input As #i
While Not EOF(1)
Line Input #i , strname
Wend
Close #1
End If
End Sub
代码2
Private Sub Command1_Click()
Dim strname As String
Open "d:\he.txt" For Input As #1
While Not EOF(1)
Line Input #1, strname
Me.Hide
Form2.Show
Form2.Print strname
Wend
Close #1
End Sub 展开
1个回答
展开全部
Private Sub Command1_Click()
Dim n As String, aa As Boolean
Dim strname As String
aa = False
n = InputBox("请输入员工的姓名或部门")
Open "C:\Users\sony\Desktop\vb\新建文本文档.txt" For Input As #i
While Not EOF(1)
Line Input #i, strname
If InStr(strname, n) Then
Form2.Print strname
aa = True
End If
Wend
Close #1
If aa Then
Me.Hide
Form2.Show
Else
MsgBox "没找到"
End If
End Sub
Dim n As String, aa As Boolean
Dim strname As String
aa = False
n = InputBox("请输入员工的姓名或部门")
Open "C:\Users\sony\Desktop\vb\新建文本文档.txt" For Input As #i
While Not EOF(1)
Line Input #i, strname
If InStr(strname, n) Then
Form2.Print strname
aa = True
End If
Wend
Close #1
If aa Then
Me.Hide
Form2.Show
Else
MsgBox "没找到"
End If
End Sub
追问
谢谢 你,修改了下,不论搜索的到都会提示“没找到“。。
追答
下面代码测试没问题,如果你是多个文件的话再自己修改
Private Sub Command1_Click()
Dim n As String, aa As Boolean
Dim strname As String
aa = False
n = InputBox("请输入员工的姓名或部门")
Open "d:\aa.txt" For Input As #1
While Not EOF(1)
Line Input #1, strname
If InStr(strname, n) Then
Form2.Print strname
aa = True
End If
Wend
Close #1
If aa Then
Form2.Show
Else
MsgBox "没找到"
End If
End Sub
Private Sub Form_Load()
Load Form2
Form2.AutoRedraw = True
Form2.Visible = False
End Sub
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询