VB中的combo控件如何实现字母查找?

2025-02-24 06:49:26
推荐回答(1个)
回答1:

既然都没有人来回答这个问题。那么我来回答好了。
刚刚花了点时间编写了代码。但是是自己粗略的写的。而不是网上复制的。一个text控件。一个Combo控件。代码如下。
里面的if语句可以换成case 语句。本机测试通过了。
如果是要在自己的程序里面打开网页。那么按照我这个思路改下就可以了。
ShellExecute 0&, vbNullString, a, vbNullString, vbNullString, vbNormalFocus
改成:
WebBrowser1.Navigate2 a

代码如下:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Dim a As String, b As String, c As String, d As String
Private Sub Combo1_Change()
a = "http://zhidao.baidu.com/q?word=" & Text1.Text & "&ct=17&pn=0&tn=ikaslist&rn=10"
b = "http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikask&rn=12&word=" & Text1.Text & "&cm=1&lm=394496"
c = "http://news.baidu.com/ns?word=" & Text1.Text & "&tn=news&from=news&cl=2&rn=20&ct=0"
d = "http://tieba.baidu.com/f?ct=&tn=&rn=&pn=&lm=&kw=" & Text1.Text & "&rs2=0&myselectvalue=1&word=ss&submit=%B0%D9%B6%C8%D2%BB%CF%C2&tb=on"
If Combo1.Text = "ss" Then
Combo1.ListIndex = 0
ShellExecute 0&, vbNullString, a, vbNullString, vbNullString, vbNormalFocus
End If
If Combo1.Text = "wy" Then
Combo1.ListIndex = 1
ShellExecute 0&, vbNullString, b, vbNullString, vbNullString, vbNormalFocus
End If
If Combo1.Text = "xw" Then
Combo1.ListIndex = 2
ShellExecute 0&, vbNullString, c, vbNullString, vbNullString, vbNormalFocus
End If
If Combo1.Text = "tb" Then
Combo1.ListIndex = 3
ShellExecute 0&, vbNullString, d, vbNullString, vbNullString, vbNormalFocus
End If
End Sub
Private Sub Combo1_Click()
a = "http://zhidao.baidu.com/q?word=" & Text1.Text & "&ct=17&pn=0&tn=ikaslist&rn=10"
b = "http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikask&rn=12&word=" & Text1.Text & "&cm=1&lm=394496"
c = "http://news.baidu.com/ns?word=" & Text1.Text & "&tn=news&from=news&cl=2&rn=20&ct=0"
d = "http://tieba.baidu.com/f?ct=&tn=&rn=&pn=&lm=&kw=" & Text1.Text & "&rs2=0&myselectvalue=1&word=ss&submit=%B0%D9%B6%C8%D2%BB%CF%C2&tb=on"

If Combo1.ListIndex = 0 Then
ShellExecute 0&, vbNullString, a, vbNullString, vbNullString, vbNormalFocus
End If
If Combo1.ListIndex = 1 Then
ShellExecute 0&, vbNullString, b, vbNullString, vbNullString, vbNormalFocus
End If
If Combo1.ListIndex = 2 Then
ShellExecute 0&, vbNullString, c, vbNullString, vbNullString, vbNormalFocus
End If
If Combo1.ListIndex = 3 Then
ShellExecute 0&, vbNullString, d, vbNullString, vbNullString, vbNormalFocus
End If
End Sub
Private Sub Form_Load()
Text1.Text = "请您输入要搜索的信息..."
Combo1.AddItem "搜索答案"
Combo1.AddItem "我要提问"
Combo1.AddItem "新闻网页"
Combo1.AddItem "贴吧知道"
End Sub
Private Sub Text1_Click()
If Text1.Text = "请您输入要搜索的信息..." Then
Text1.Text = ""
End If
End Sub