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 LongPrivate Sub Command1_Click() Call ShellExecute(Form1.hwnd, "open", "http://changbuy.com/listzt.asp?id=1275", vbNullString, vbNullString, &H0) End Sub'其中id=1275即为参数部分
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 LongPrivate Sub Command1_Click() ShellExecute 0, "open", "http://www.baidu.com/baidu?w=" & Text1.Text, 0, 0, 0 End Sub
1、建个表,类型如下: ID KEY URL id是自动编号,KEY是关键字,URL是网址链接 例如KEY="彩屏GSM手机",它在www.changbuy.com的链接地址是“http://www.changbuy.com/class.asp?lx=small&anid=32&nid=271”那么就是URL=“http://www.changbuy.com/class.asp?lx=small&anid=32&nid=271” 2、输入关键字查询时候,就通过在表内查询,得到对应的URL,用上面几位老兄给的代码即可让其访问对应的网页 例如输入“手机” SQL语句就是SELECT URL FROM URLTABLE WHERE KEY LIKE "%手机%" 你可以自己组合SQL语句,不要问我怎么写 得到的URL如果有多条,可以列出来,让人选择,也可以就直接显示第一条,看你怎么做了。 最后就是用上面的方法调IE即可 下面的变量UrlStr要先将数据库里得到的链接赋值给它。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 LongPrivate Sub Command1_Click() ShellExecute 0, "open", UrlStr, 0, 0, 0 End Sub
http://www.changbuy.com/ 里的查询是Post方式,不能用这种方法的。
原来它的ASP是通过Request("classid")来读的,所以可以实现,以下是Form1.frmVERSION 5.00 Begin VB.Form Form1 Caption = "阿里巴巴在线查询" ClientHeight = 2340 ClientLeft = 60 ClientTop = 345 ClientWidth = 6210 LinkTopic = "Form1" ScaleHeight = 2340 ScaleWidth = 6210 StartUpPosition = 3 'Windows Default Begin VB.TextBox Text1 Height = 330 Left = 3990 TabIndex = 2 Top = 585 Width = 1575 End Begin VB.ComboBox Combo1 Height = 315 ItemData = "Form1.frx":0000 Left = 1065 List = "Form1.frx":0049 TabIndex = 1 Text = "Combo1" Top = 570 Width = 1950 End Begin VB.CommandButton Command1 Caption = "查询" Height = 450 Left = 4095 TabIndex = 0 Top = 1545 Width = 1215 End Begin VB.Label Label2 Caption = "类型" Height = 345 Left = 510 TabIndex = 4 Top = 615 Width = 630 End Begin VB.Label Label1 Caption = "关键字" Height = 345 Left = 3195 TabIndex = 3 Top = 645 Width = 630 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option ExplicitPrivate 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 Private Const SW_SHOWNORMAL = 1Dim value As String Private Sub Command1_Click() Dim classid As Long If Combo1.ListIndex = 0 Then classid = 0 Else classid = Combo1.ListIndex + 31 End If
ShellExecute Me.hWnd, vbNullString, "http://www.changbuy.com/research.asp?anclassid=" & classid & "&searchkey=" & Text1.Text, vbNullString, vbNullString, SW_SHOWNORMAL End SubPrivate Sub Form_Load() Combo1.ListIndex = 0 End Sub
' 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'【说明】
' 查找与指定文件关联在一起的程序的文件名'【返回值】
' Long,非零表示成功,零表示失败。会设置GetLastError'【参数表】
' hwnd ----------- Long,指定一个窗口的句柄,有时候,windows程序有必要在创建自己的主窗口前显示一个消息框' lpOperation ---- String,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它' lpFile --------- String,想用关联程序打印或打开一个程序名或文件名' lpParameters --- String,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数' lpDirectory ---- String,想使用的完整路径' nShowCmd ------- Long,定义了如何显示启动程序的常数值。
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 LongPrivate Sub Label2_Click() Call ShellExecute(Form1.hwnd, "open", "http://www.YourWebSite.com?User=XXX&Pwd=YYY", vbNullString, vbNullString, &H0)End Sub
Call ShellExecute(Form1.hwnd, "open", "http://changbuy.com/listzt.asp?id=1275", vbNullString, vbNullString, &H0)
End Sub'其中id=1275即为参数部分
http://localhost/dd.asp?dd=vb的得到的值,在调用ASP内置对象进行传送和ASP通讯,
response.redirect "dd.asp?dd="&trim(dd)&"'"
ShellExecute 0, "open", "http://www.baidu.com/baidu?w=" & Text1.Text, 0, 0, 0
End Sub
ID KEY URL
id是自动编号,KEY是关键字,URL是网址链接
例如KEY="彩屏GSM手机",它在www.changbuy.com的链接地址是“http://www.changbuy.com/class.asp?lx=small&anid=32&nid=271”那么就是URL=“http://www.changbuy.com/class.asp?lx=small&anid=32&nid=271”
2、输入关键字查询时候,就通过在表内查询,得到对应的URL,用上面几位老兄给的代码即可让其访问对应的网页
例如输入“手机”
SQL语句就是SELECT URL FROM URLTABLE WHERE KEY LIKE "%手机%"
你可以自己组合SQL语句,不要问我怎么写
得到的URL如果有多条,可以列出来,让人选择,也可以就直接显示第一条,看你怎么做了。
最后就是用上面的方法调IE即可
下面的变量UrlStr要先将数据库里得到的链接赋值给它。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 LongPrivate Sub Command1_Click()
ShellExecute 0, "open", UrlStr, 0, 0, 0
End Sub
Begin VB.Form Form1
Caption = "阿里巴巴在线查询"
ClientHeight = 2340
ClientLeft = 60
ClientTop = 345
ClientWidth = 6210
LinkTopic = "Form1"
ScaleHeight = 2340
ScaleWidth = 6210
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text1
Height = 330
Left = 3990
TabIndex = 2
Top = 585
Width = 1575
End
Begin VB.ComboBox Combo1
Height = 315
ItemData = "Form1.frx":0000
Left = 1065
List = "Form1.frx":0049
TabIndex = 1
Text = "Combo1"
Top = 570
Width = 1950
End
Begin VB.CommandButton Command1
Caption = "查询"
Height = 450
Left = 4095
TabIndex = 0
Top = 1545
Width = 1215
End
Begin VB.Label Label2
Caption = "类型"
Height = 345
Left = 510
TabIndex = 4
Top = 615
Width = 630
End
Begin VB.Label Label1
Caption = "关键字"
Height = 345
Left = 3195
TabIndex = 3
Top = 645
Width = 630
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate 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
Private Const SW_SHOWNORMAL = 1Dim value As String
Private Sub Command1_Click()
Dim classid As Long If Combo1.ListIndex = 0 Then
classid = 0
Else
classid = Combo1.ListIndex + 31
End If
ShellExecute Me.hWnd, vbNullString, "http://www.changbuy.com/research.asp?anclassid=" & classid & "&searchkey=" & Text1.Text, vbNullString, vbNullString, SW_SHOWNORMAL
End SubPrivate Sub Form_Load()
Combo1.ListIndex = 0
End Sub