探索VB6.0与Web的相结合设计方法

前端之家收集整理的这篇文章主要介绍了探索VB6.0与Web的相结合设计方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

近来,在尝试一种WEb下Table数据导入Access表中的操作,是用VB6.0结和webbrowser控件做的。各个界面如下:

图1

本程序的初衷,【将数据导入控件显示】按钮是将【深圳市场】每天交易信息,网页中导出并显示在listview控件中;,【控件数据进入Table】按钮是将所显示数据添加到Access的表中,(图2)为表的结构;【控件显示Table数据】按钮,做一下清屏后,将Access数据表的记录堵到listView控件中。

以上是我做实验的过程。但美中不足的地方是【看图3,图4】,还要同时收集【该股票】当日买卖的大宗数据,包括:金额(买卖),所在营业部等信息。这点我正在实验,其数据向另一个Access中添加,备留分析用。目前,仍未【通过】!故请平台上的专家,给予帮助!!谢谢!

图3:

图4:

'需要添加一个webbrowser控件 和一个按钮
'引用两个库,在菜单的工程-引用里,找到
'1.Microsoft HTML object library
'2.Microsoft activex data object 2.5/2.6

示意图:


Private Sub Command1_Click() '链接IE网络进入[深圳市场投资界面]
ListView1.ListItems.Clear
WebBrowser1.Navigate "http://www.szse.cn/main/disclosure/news/xxlb/index.shtml?txtStockCodeORname="
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,URL As Variant) '过程调用参数:[原代码]
'定义VAR
Dim doc As MSHTML.HTMLDocument
Set doc = WebBrowser1.Document
Dim table As MSHTML.HTMLTable
Dim lrow As MSHTML.HTMLTableRow
Dim cel As MSHTML.HTMLTableCell
Set table = doc.getElementById("REPORTID_tab1")
Dim Conn As ADODB.Connection

Dim FLD() As String '定义数组:字符串
'Access的参数进行设置
Set Conn = CreateObject("ADODB.Connection")
Conn.Open "provider=microsoft.jet.oledb.4.0;data source=e:/065/DB1.MDB"
'
Set lrow = table.rows(0) '初值=0//定为要查找的位置。
ReDim FLD(0 To lrow.cells.length) As String
Dim i As Integer '循环变量
Dim tbname As String '表名变量
Dim sql As String '定义字段名
tbname = InputBox("输入导入数据库的新建的表的名字","table1") '表名
For i = 0 To lrow.cells.length - 1
FLD(i) = Replace(Replace(Replace(lrow.cells(i).innerText,"/",""),"(",")","")
sql = sql & FLD(i) & " varchar(255),"
Next i

sql = Left(sql,Len(sql) - 1)
Conn.Execute "create table " & tbname & " (" & sql & ")"
Dim J As Integer
sql = ""
For i = 0 To lrow.cells.length - 1
sql = sql & FLD(i) & ","
Next i
sql = Left(sql,Len(sql) - 1)
Dim vlist As String
'添加记录过程
For i = 1 To table.rows.length - 1 '总行数-1
vlist = ""
Set lrow = table.rows(i)
For J = 0 To lrow.cells.length - 1
vlist = vlist & "'" & lrow.cells(J).innerText & "',"
Next J
vlist = Left(vlist,Len(vlist) - 1)
Conn.Execute "insert into " & tbname & " (" & sql & ") values (" & vlist & ")"

Next i
Conn.Close
Set Conn = Nothing
MsgBox "数据文件添加记录成功!!",vbOKCancel,"运行提示" 'app
End Sub

---------------------------------------------------------------------------------

希望本实例对大家有益,让我们互相交流,共同提高吧!

原文链接:https://www.f2er.com/vb/261798.html

猜你在找的VB相关文章