1、新建一個標(biāo)準(zhǔn)的VB EXE工程,只有一個Form,F(xiàn)orm上有兩個按鈕:Command1和Command2。
平山網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),平山網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為平山上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的平山做網(wǎng)站的公司定做!
2、雙擊Command1添加如下代碼
Private Sub Command1_Click()
Dim strFile? ? ?As String
Dim intFile? ? ?As Integer
Dim strData? ? ?As String
strFile = "c:\學(xué)生成績.txt"
intFile = FreeFile
Open strFile For Input As intFile
strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)
Debug.Print strData
Close intFile
End Sub
3、按F8開始單步調(diào)試代碼,點擊Command1,進入單步調(diào)試功能,
4、多次按下F8或直接按下F5運行完成,就完成了讀取文本文件內(nèi)容并輸出到立即窗口。
Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String
'啟動一次具體的數(shù)據(jù)采集工作,返回采集到的HTML內(nèi)容:要求必須輸入帶://的全地址數(shù)據(jù)
On Error Resume Next
Dim Str_WebContent As String = "請輸入查找網(wǎng)站地址."
Dim wb As WebClient = New WebClient() '//創(chuàng)建一個WebClient實例
If mWebsiteUrl.IndexOf("://") 0 Then
'//獲取或設(shè)置用于對向 Internet 資源的請求進行身份驗證的網(wǎng)絡(luò)憑據(jù)。(可有可無)
wb.Credentials = CredentialCache.DefaultCredentials
'//從資源下載數(shù)據(jù)并返回字節(jié)數(shù)組。(加@是因為網(wǎng)址中間有"/"符號)
Dim pagedata As Object = wb.DownloadData(mWebsiteUrl)
'//轉(zhuǎn)換字符
If mWebsiteType Then
Str_WebContent = Encoding.Default.GetString(pagedata)
Else
Str_WebContent = Encoding.UTF8.GetString(pagedata)
End If
End If
Return Str_WebContent '提取出來新聞內(nèi)容,刪除Body前后的多余內(nèi)容,同時補充上該 Body標(biāo)記,形成完整的內(nèi)容 Str_WebContent '
End Function
用正則表達式吧,首先導(dǎo)入命名空間System.Text.RegularExpressions,用Webbrowser載入頁面,使用vb.net的代碼如下:
Dim iTable As String = WebBrowser1.Document.Body.InnerHtml
Dim str_xm1 As String = Regex.Match(Regex.Matches(iTable, "td.*?/td").Item(6).Value, ".*?").Value
這樣str_xm1就是你要的內(nèi)容。
孩子,如果你從你單擊事件上下手,就好辦了,先弄明白,點擊了什么,datagridview點擊,可以獲取單擊的值,好辦,用SQL語句去查詢單擊的這個值,把查到的結(jié)果再交給你要處理的地方,我常這么干。我從來不曉得什么表與表之間的關(guān)聯(lián),或者關(guān)系表什么鬼東西,但是我也可以操作很多張表,把它們的結(jié)果集一起顯示出來。
Dim 表1 As New DataSet
Dim 對象1 As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select top * from表名 where 字段名 = '" DataGridView1.CurrentCell.Value "' ", 數(shù)據(jù)源)
對象1.Fill(表1, " 表名")
DataGridView2.DataSource = 表1.Tables(" 表名")
表1 = Nothing
對象1 = Nothing
如果寫成這樣,還嫌不夠,一定要按你的意思去寫,那我真的要瘋了。
這個例子,就是把表格1點擊的值查一個結(jié)果集,在表格2上顯示,不知有沒有你想要的表達式?