Are you building this in Word VBA or are you calling Word from your application or you got your string in your app and need to handle it?
Please any code you've got, for us to see how you've got this far.
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
I think that calling Word.Application requires word to be installed - and obviously licensed.
Anyway:
Sub ShallReadRoutine()
dim keywords() = {"shall read","test1","test2")
for each key as string in keywords
LEDDisplaySearch = Procedure.IndexOf(key)
if LEDDisplaySearch <> -1
TopDisplay = procedure.substring(LEDDisplaySearch + 10, 7)
BottomDisplay = Procedure.substring(LEDDisplaySearch + 18,7)
select case key
case "shall read"
UUTBox.RichTextBox4.text = TopDisplay
UUTBox.RichTextBox3.text = BottomDisplay
case else
cobj(key & "upper").text = TopDisplay
cobj(key & "lower").text = BottomDisplay
end if
next
This might give you an idea.
If you are looking for the next "shall read" part then you should use the overloaded IndexOf and specify as startIndex the last index or the last index + how many chars you need to.
Try to use meaningfull names in your objects. RichTextBox4 will only get you lost inside your code and will make troubleshooting or future releases harder.
In the case else part I've used test1upper, test1lower, test2upper and test2lower as textboxes (or richtextboxes) and used the same code for both sets of objects. If this isn't your case, you can repeat the case "shall read" part with different objects or whatever.
Please note that the above code hasn't been tested and may contain typos or other errors.
Good luck.
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
Hi,
As adam_k said if you are using the word libraries and interop to access word, the users machine must have a copy of Word installed.
Furthermore, if you specifically include references to a Word library you are depending on the user having the same version of Word installed i.e. Word 2003 uses a different library than Word 2010
To get round the library issue it is better to use late binding to access word:
'Example using an included reference to Word library - depends on client having same version
Imports Microsoft.Interop.Word
dim MyWord as Word.Application
dim MyDoc as Word.Document
MyWord = new Word.Application
MyDoc = new Word.Document 'I don't think you actually need this line
MyDoc = MyWord.Documents.Open (FilePath)
'Example using late binding - uses whatever version found on client
dim MyWord as Object
dim MyDoc as Object
MyWord = createobject("Word.Application")
'create object will go and find whatever program string matches
MyDoc = MyWord.Documents.Open(FilePath)
G_Waddell
Practically a Master Poster
619 posts since Nov 2009
Reputation Points: 107
Solved Threads: 93
Skill Endorsements: 5
The dim keywords() = {..} will declare an array.
The for each key as string in keywords will step through the array's ellements.
This way you can use the same code and save yourself a huge pile of if...else if.... else...
If you can't go with Word, perhaps it's time to get back to why do you use a word file? Can't it be a simple text file?
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
So a work associate told my that if I add the Microsoft Word Object Library to my reference a user would be able to strip the word document text and process the data as a new string. It seems I was misinformed. There is no way my company is going to pay the Microsoft Word licensing on the 11 computers I am planning to purchase for this project. Any advice on a work-around?
_
\mc-000\WebFTP\Drawings\LoveCalProcedures\65726210test.doc"
Does the Word Document absolutely need to be stored in the Word 97-2003 "doc" format? If it could be stored in the newer "docx" format, you can use the Open XML SDK 2.0 for Microsoft Office to read the file without any licensing issues.
Retrieving the document text is as simple as:
Dim wpdoc As DocumentFormat.OpenXml.Packaging.WordprocessingDocument = WordprocessingDocument.Open("D:\My Documents\programming.docx", isEditable:=False)
Dim body As DocumentFormat.OpenXml.Wordprocessing.Body = wpdoc.MainDocumentPart.Document.Body
Dim doctext As String = body.InnerText
wpdoc.Close()
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13
In the .doc format the text itself is stored in plain text, a hex editor should be able to let you see the control codes that signal the text. With that you can parse the file to find the text.
tinstaafl
Nearly a Posting Virtuoso
1,329 posts since Jun 2010
Reputation Points: 355
Solved Threads: 233
Skill Endorsements: 14
As the guys said above, there are ways and means to get around using the word application... It just means you will not be using the Interop application.
G_Waddell
Practically a Master Poster
619 posts since Nov 2009
Reputation Points: 107
Solved Threads: 93
Skill Endorsements: 5
If your issue is solved, please mark this thread as solved.
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
Question Answered as of 3 Months Ago by
adam_k,
G_Waddell,
tinstaafl
and 1 other