两个word文件,搜寻其中一个word的关键字,然后输出给另一个word 关键字和页码
两个word文件,搜索其中一个word的关键字,然后输出给另一个word 关键字和页码
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBox1.AllowDrop = True
TextBox2.AllowDrop = True
End Sub
Private Sub TextBox1DragEnter(sender As Object, e As DragEventArgs) Handles TextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files As String()
Try
files = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.TextBox1.Text = files(files.Length - 1)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
End If
End Sub
Private Sub TextBox2DragEnter(sender As Object, e As DragEventArgs) Handles TextBox2.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files As String()
Try
files = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.TextBox2.Text = files(files.Length - 1)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
End If
End Sub
Public Sub GetPageAsync(pageNumber As Integer, userState As Object)
End Sub
Public Sub Textbox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Dim p As String = InputBox("请输入搜索关键字")
Try
Dim fs As New System.IO.FileStream(TextBox1.Text, System.IO.FileMode.Open)
Dim sr As New System.IO.StreamReader(fs)
Dim s As Integer
Dim str As String
Do Until sr.EndOfStream
str = sr.ReadLine
If str.Contains(p) Then
Call GetPageAsync(s, p)
FileOpen(FreeFile, TextBox2.Text, OpenMode.Output)
WriteLine(FreeFile, s - -----------p)
End If
Loop
sr.Close()
fs.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
End Class
这是我写的代码。。。搜索和页码那块不太会写求解
还有别的地方写错望大神在源码上改改
这个程序简单就做了两个textbox
------解决思路----------------------
参考:http://zhidao.baidu.com/link?url=CM8_46V49z0Rtzc8yyxsPyCskwRAkN3Az5S2zsKV0Yl2uF2N_QyTa9OabQDcbxyHcBcH3FCHlOVylFhTpGIoxq
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBox1.AllowDrop = True
TextBox2.AllowDrop = True
End Sub
Private Sub TextBox1DragEnter(sender As Object, e As DragEventArgs) Handles TextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files As String()
Try
files = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.TextBox1.Text = files(files.Length - 1)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
End If
End Sub
Private Sub TextBox2DragEnter(sender As Object, e As DragEventArgs) Handles TextBox2.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files As String()
Try
files = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.TextBox2.Text = files(files.Length - 1)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try
End If
End Sub
Public Sub GetPageAsync(pageNumber As Integer, userState As Object)
End Sub
Public Sub Textbox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Dim p As String = InputBox("请输入搜索关键字")
Try
Dim fs As New System.IO.FileStream(TextBox1.Text, System.IO.FileMode.Open)
Dim sr As New System.IO.StreamReader(fs)
Dim s As Integer
Dim str As String
Do Until sr.EndOfStream
str = sr.ReadLine
If str.Contains(p) Then
Call GetPageAsync(s, p)
FileOpen(FreeFile, TextBox2.Text, OpenMode.Output)
WriteLine(FreeFile, s - -----------p)
End If
Loop
sr.Close()
fs.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
End Class
这是我写的代码。。。搜索和页码那块不太会写求解
还有别的地方写错望大神在源码上改改
这个程序简单就做了两个textbox
------解决思路----------------------
参考:http://zhidao.baidu.com/link?url=CM8_46V49z0Rtzc8yyxsPyCskwRAkN3Az5S2zsKV0Yl2uF2N_QyTa9OabQDcbxyHcBcH3FCHlOVylFhTpGIoxq