用XML写的留言录(vb.net)(五)

类别:.NET开发 点击:0 评论:0 推荐:

作者:fx_blog(CSDN)

日期:2005-5-22

标题:威人留言录(v1.8)

注意:转贴一定注明作者及出处

'*****************************************开始****************************

'现在来完成第五部分,留言查询*******

'首先新建一个窗体

'大家自己建吧,现在应该是form6了

'双击"查询留言"按钮

'写入以下代码(Form6内的控件都要设置好)

'       

If TextBox3.Text = "" Then
            MessageBox.Show("请输入搜索关键字")
            Exit Sub
        End If
        Dim searchform As New Form6
        searchform.TextBox1.Text = Me.TextBox3.Text
        searchform.Show()

'现在回到Form6窗体

'首先进入Form6_Load(...)

'写入以下代码....

Me.Text = "查询留言-关键字: " & TextBox1.Text
        Dim doc As XmlDocument = New XmlDocument
        doc.Load("info.xml")
        Dim match As String
        match = TextBox1.Text
        Dim regular As Regex = New Regex(match)
       Dim liuyuaninfo As XmlNodeList
        liuyuaninfo = doc.GetElementsByTagName("userliuyuan")

        Dim i As Integer

        TextBox1.Text += "以下是相似的记录" & vbCrLf
        TextBox1.Text += "==================================" & vbCrLf
        For i = 0 To userid.Count - 1
            While regular.IsMatch(liuyuaninfo(i).InnerText)
                TextBox1.Text += "留言: " & liuyuaninfo(i).InnerText & vbCrLf
                TextBox1.Text += "=======================================" & vbCrLf
                Exit While
            End While
        Next

'现在双击"关键字查询"按钮

'输入以下代码(其实和上面的一模一样)

Me.Text = "查询留言-关键字: " & TextBox1.Text
        Dim doc As XmlDocument = New XmlDocument
        doc.Load("info.xml")
        Dim match As String
        match = TextBox1.Text
        Dim regular As Regex = New Regex(match)
       Dim liuyuaninfo As XmlNodeList
        liuyuaninfo = doc.GetElementsByTagName("userliuyuan")

        Dim i As Integer

        TextBox1.Text += "以下是相似的记录" & vbCrLf
        TextBox1.Text += "==================================" & vbCrLf
        For i = 0 To userid.Count - 1
            While regular.IsMatch(liuyuaninfo(i).InnerText)
                TextBox1.Text += "留言: " & liuyuaninfo(i).InnerText & vbCrLf
                TextBox1.Text += "=======================================" & vbCrLf
                Exit While
            End While
        Next

'好了查询功能完成了,到现在为止,五部分已经全部完成.

'如果大家有问题请留言.

'界面如下

本文地址:http://com.8s8s.com/it/it40899.htm