[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.6

vb.net search through word documents

Asked by wardo123 in Microsoft Visual Studio Express, Microsoft Visual Basic.Net

Tags: Visual Basic, programming VB.net, VB

I need to search through thousands of Word docuemnts that list user info.  I wrote a VB program using Microsoft Visual Basic 2008 Express Edition, that will search for a user name in each of the documents.  This search is done by using StreamReader to load each file and then searching the file for a search string.  If this string is found I then open the workd docuemnt using Microsoft.Office.Interop.Word and pull out data to load into ta ListBox.
My problem is that some of the Documents actually have the user names in the header informaion, and it looks like StreamReader doesn't look at header information in Word becasue I never find a user if they are only listed in the header information.  Anyone know of a way around this?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
Private Function CheckFiles(ByVal FileName As String, ByVal SearchWord As String) As Boolean
        'Searching for matching document and then pulling out the User name and Bith Date
        Dim IsWordFound As Boolean = False
        Dim strLine, strUserName, strBDate, orgStrLine As String
        Dim FileContents As String = String.Empty
        Dim FileStreamReader As StreamReader
        Dim MyCrLf As String
        Const MyCr As String = Microsoft.VisualBasic.ControlChars.Cr
        Const MyTab As String = Microsoft.VisualBasic.ControlChars.Tab
        MyCrLf = Chr(13) + Chr(10)
        'Dim fulWordFile As New Microsoft.Office.Interop.Word.Application
        'Dim Doc As Microsoft.Office.Interop.Word.Application
 
        Dim bFlag As Boolean = False
        Dim bFlagName As Boolean = False
        Dim bFlagBirth As Boolean = False
        Try
            FileStreamReader = New StreamReader(FileName)
            FileContents = FileStreamReader.ReadToEnd()
        Catch ex As Exception
            MsgBox(ex.ToString)
            IsWordFound = False
        Finally
            If Not (FileStreamReader Is Nothing) Then
                FileStreamReader.Close()
            End If
        End Try
        If FileContents.IndexOf(SearchWord) > 0 Then
            'IndexOf returns -1 of not found and 0 if the textVal is empty
            Dim lstItem As New ListViewItem
            Try
                Dim objWord As New Word.Application
                Dim objDoc As Word.Document
                objDoc = objWord.Documents.Open(FileName:=FileName, ReadOnly:=True)
                objDoc.Activate()
                strLine = objDoc.Content.Text
                'orgStrLine = strLine
                Do While Not bFlag
                    If InStr(UCase(strLine), "PATIENT NAME:") Or InStr(UCase(strLine), "BIRTH DATE:") Then
                        Dim intPatient, intBDay, intPatientSpace, intBDaySpace, intLength As Integer
                        Dim strPatient, strBDay As String 'temp string holders
 
                        If InStr(UCase(strLine), "PATIENT NAME:") Then
                            'To find the patient name we will trim the string down to just after the Patient Name: statment
                            'then we will find the space that follows the coma and finally the end space
                            intPatient = InStr(UCase(strLine), "PATIENT NAME:")
                            intLength = Microsoft.VisualBasic.Len(strLine)
                            strUserName = Microsoft.VisualBasic.Right(strLine, (intLength - intPatient) - 13)
                            intLength = Microsoft.VisualBasic.Len(strUserName)
                            intPatient = InStr(UCase(strUserName), "BIRTH DATE:")
                            strPatient = Microsoft.VisualBasic.Left(strUserName, intPatient - 1)
                            strPatient = Replace(strPatient, MyTab, "")
                            strUserName = strPatient.Trim
 
                            lstItem.Text = strUserName
                            lstItem.Tag = FileName
                            'lstItem.SubItems.Add = FileName
                            bFlagName = True
                        End If
                        If InStr(UCase(strLine), "BIRTH DATE:") Then
                            intBDay = InStr(UCase(strLine), "BIRTH DATE:")
                            intLength = Microsoft.VisualBasic.Len(strLine)
                            If InStr(UCase(strLine), "PATIENT ID") Or InStr(UCase(strLine), "MEDICAL RECORD #:") Then
                                'strip everthing before the date, using 11 as a offset becasue there are 11 letters in Birth Date: string
                                strBDate = Microsoft.VisualBasic.Right(strLine, (intLength - intBDay) - 11)
                                'orgStrLine = Microsoft.VisualBasic.Right(strLine, (intLength - intBDay) - 13)
                                intLength = Microsoft.VisualBasic.Len(strBDate)
                                intBDay = InStr(UCase(strBDate), MyCr)
                                'intBDay = InStr(UCase(strBDate), "PATIENT ID")
                                strBDay = Microsoft.VisualBasic.Left(strBDate, intBDay - 1)
                                strBDay = Replace(strBDay, MyTab, "")
                                strBDate = strBDay.Trim
                            Else
                                strBDate = "Not Found"
                            End If
                            lstItem.SubItems.Add(strBDate)
                            lstItem.Tag = FileName
                            bFlagBirth = True
                        End If
                            lstDocs.Items.Add(lstItem)
 
                            'Releasing the evil COM object
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(objDoc)
                            objDoc = Nothing
                            'closing the hidden Word document
                            objWord.Application.Quit()
                            objWord = Nothing
 
                            lstDocs.Refresh()
 
                        End If
                        If bFlagName And bFlagBirth Then
                            bFlag = True
                        End If
                Loop
 
                IsWordFound = True
            Catch ex As Exception
                MsgBox(ex.ToString)
                IsWordFound = False
            Finally
                If Not (FileStreamReader Is Nothing) Then
                    FileStreamReader.Close()
                End If
            End Try
        End If
        Return IsWordFound
        FileContents = String.Empty
    End Function
[+][-]09/22/09 05:28 AM, ID: 25391968Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Microsoft Visual Studio Express, Microsoft Visual Basic.Net
Tags: Visual Basic, programming VB.net, VB
Sign Up Now!
Solution Provided By: CodeCruiser
Participating Experts: 1
Solution Grade: B
 
[+][-]09/25/09 11:14 AM, ID: 25425629Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/26/09 02:56 AM, ID: 25429346Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/29/09 06:50 PM, ID: 25455079Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/30/09 12:57 AM, ID: 25456371Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/30/09 07:07 PM, ID: 25465501Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/01/09 12:54 AM, ID: 25466649Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10/03/09 06:45 AM, ID: 25485380Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/03/09 07:04 AM, ID: 25485440Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/03/09 06:05 PM, ID: 25487735Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/05/09 12:42 AM, ID: 25493104Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10/08/09 06:55 PM, ID: 25531868Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/09/09 12:54 AM, ID: 25533010Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/09/09 07:42 PM, ID: 25540526Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 01:33 AM, ID: 25549369Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 04:56 PM, ID: 25556062Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/13/09 12:50 AM, ID: 25557745Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/15/09 10:40 AM, ID: 25582826Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/16/09 01:02 AM, ID: 25587655Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/18/09 12:45 PM, ID: 25601102Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/19/09 12:13 AM, ID: 25603062Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/19/09 01:05 PM, ID: 25608475Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/20/09 12:29 AM, ID: 25611685Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/21/09 07:09 AM, ID: 25624114Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/21/09 07:11 AM, ID: 25624135Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/25/09 07:37 AM, ID: 25656742Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625