473,467 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Selecting text to the right of a specific string

15 New Member
Hi,

I am using some code I found online to find a text string in a PDF.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command3_Click()
  3. 'IAC objects
  4. Dim gAvDoc As Object
  5.  
  6. 'variables
  7. Dim Resp 'For message box responses
  8. Dim gPDFPath As String
  9. Dim sText As String 'String to search for
  10. Dim sStr As String 'Message string
  11. Dim foundText As Integer 'Holds return value from "FindText" method
  12.  
  13. 'hard coding for a PDF to open, it can be changed when needed.
  14. gPDFPath = "C:\Documents and Settings\user\Desktop\testsearchpdf.pdf"
  15.  
  16. 'Initialize Acrobat by creating App object
  17. Set gApp = CreateObject("AcroExch.App")
  18. gApp.Hide
  19.  
  20. 'Set AVDoc object
  21. Set gAvDoc = CreateObject("AcroExch.AVDoc")
  22.  
  23. ' open the PDF
  24. If gAvDoc.Open(gPDFPath, "") Then
  25. sText = "SD15"
  26. 'FindText params: StringToSearchFor, caseSensitive (1 or 0), WholeWords (1 or 0), ResetSearchToBeginOfDocument (1 or 0)
  27. foundText = gAvDoc.FindText(sText, 1, 0, 1) 'Returns -1 if found, 0 otherwise
  28.  
  29. Else
  30. ' if failed, show error message
  31. Resp = MsgBox("Cannot open" & gPDFPath, vbOKOnly)
  32. End If
  33. If foundText = -1 Then
  34. 'compose a message
  35. sStr = "Found " & sText
  36. Resp = MsgBox(sStr, vbOKOnly)
  37. Else
  38. ' if failed, show error message
  39. Resp = MsgBox("Cannot find" & sText, vbOKOnly)
  40. End If
  41. gApp.Show
  42. gAvDoc.BringToFront
  43. End Sub
  44.  
What I need to do is select the text that is to the right of the text string, lets say 15 characters that appear to the right of the string. Any suggestions?

Thanks,

RugbyKorn
Mar 27 '13 #1

✓ answered by ADezii

Do you have any suggestions for how I can turn the entire contents of the PDF into a string so that I can then use the inStr function?
I know of no such Method to accomplish this.

8 4084
Rabbit
12,516 Recognized Expert Moderator MVP
Use the Right function.
Expand|Select|Wrap|Line Numbers
  1. Right("string", #)
Where # is how many characters you want from the right.
Mar 27 '13 #2
Rugbykorn
15 New Member
Hi Rabbit,

I appreciate you taking the time to review my post. I was hoping it would be that simple but here is what I ran into. The code I pasted uses
Expand|Select|Wrap|Line Numbers
  1. gAvDoc.FindText("String", 1, 0, 1)
to locate the string I want. However that function is simply a true false (0 or 1) as to whether the string I specify exists. What I need to do is search for the "string" and anything to the right of it, so something like
Expand|Select|Wrap|Line Numbers
  1.  "String" & * 
. However I can't use the FindText function since that will simply tell me if the string exists, and not what is contained in the wildcard section of it.

I hope this makes sense. I am more then happy to clarify anything I just wrote if you would like some more background on what I am trying to achieve.

Thanks!
Mar 27 '13 #3
ADezii
8,834 Recognized Expert Expert
Here is the Basic Logic for finding a Sub-String within a String, then outputting the 15 Characters after the Sub-String. The Code makes many Assumptions that I will not go into at this point.
Expand|Select|Wrap|Line Numbers
  1. Const conTEST_String As String = "AAAAA AA AAAAA  AAAAA  AAARDK12YE YOU FOUND ME  IGNORE  THER  EST^^&%OFTHIS"
  2. Const conSTING_TO_FIND As String = "RDK12"
  3. Dim intStartPos As String
  4.  
  5. intStartPos = InStr(conTEST_String, conSTING_TO_FIND)
  6.  
  7. If intStartPos = 0 Then Exit Sub
  8.  
  9. Debug.Print Mid$(conTEST_String, intStartPos + Len(conSTING_TO_FIND), 15)
OUTPUT (15 characters after Search String):
Expand|Select|Wrap|Line Numbers
  1. YE YOU FOUND ME
Used within the Context of a Traditional Access Text Box:
Expand|Select|Wrap|Line Numbers
  1. Const conSTING_TO_FIND As String = "RDK12"
  2. Dim intStartPos As String
  3.  
  4. intStartPos = InStr(Me![txtTest], conSTING_TO_FIND)
  5.  
  6. If intStartPos = 0 Then Exit Sub
  7.  
  8. With Me![txtTest]
  9.   .SetFocus
  10.   .SelStart = (intStartPos + Len(conSTING_TO_FIND)) - 1
  11.     .SelLength = 15
  12. End With
Mar 27 '13 #4
Seth Schrock
2,965 Recognized Expert Specialist
@Rabbit I think that OP is wanting the characters TO the right not FROM the right, in which case the Mid() function would be needed. However, I don't see in the code provided how to get the string value. I only see that it says that it found the search string or not, but not where it would return the string found in the PDF.
Mar 27 '13 #5
Rugbykorn
15 New Member
Hi Seth,

Again, thank you everyone for taking a look at this as I would love to figure this out. At the bottom of the code a MsgBox is displayed showing the value that was searched for, but as you said its not displaying the actual value found. I know what I need to do, which is to search for a value, and identify the characters next to that value, say the 10 characters to the right of it. However I don't now how to index the whole PDF so that I can then use the inStr function as @ADezii suggested.

RugbyKorn
Mar 27 '13 #6
Rugbykorn
15 New Member
Hi @ADezii,

Do you have any suggestions for how I can turn the entire contents of the PDF into a string so that I can then use the inStr function?

RugbyKorn
Mar 27 '13 #7
ADezii
8,834 Recognized Expert Expert
Do you have any suggestions for how I can turn the entire contents of the PDF into a string so that I can then use the inStr function?
I know of no such Method to accomplish this.
Mar 28 '13 #8
Rugbykorn
15 New Member
@ADezii,

I'm thinking that may be a dead end. I am now trying to do this with an XPS document instead of a PDF. I will open a new comment thread. Thanks for taking the time to read.

RugbyKorn
Mar 28 '13 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cassandra.flowers | last post by:
Hi, I am using VB6 and want to extract text from a string. But ONLY take out words that begin with 't' or 'd'. The mainstring is input by the user into 'txtMain' and then by clicking a command...
4
by: RelaxoRy | last post by:
Is there any way to stop someone getting their mouse and selecting text on a page (without making the text an image of course). Is it possible to trap and stop click-and-drag functionality from...
2
by: Lloyd | last post by:
I am trying to insert text in a text area. I need to insert one set of values on the left side of the text area and have corresponding values on the left side of the text area in an even column....
1
by: Kim | last post by:
Hello, I am selecting data from a text file with the following statement: "INSERT INTO SELECT * FROM " & sSource & " IN '' " & _ "'text;Database=" & sPath & ";FMT=Delimited;HDR=No' " & _...
1
by: robboll | last post by:
Using MS Access 2003 I am looking for a function that will search the entire Tables Collection for a specific string in text or memo fields. For example if I enter "widget" it interrogates the...
2
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the...
3
by: Coffee | last post by:
I have asked this before, but the offered solution did not work. I want to have a command button, that transfers any text from a textbox to a variable which is an array. so that i can print out...
4
by: boris.smirnov | last post by:
Hallo all, I have tried for a couple of hours to solve my problem with re but I have no success. I have a string containing: "+abc_cde.fgh_jkl\n" and what I need to become is...
2
by: Pete | last post by:
I need to create a single query (Not a SQL query) against a single table that counts the number of records in the table, where the single field "tmp" contains specific string values If the field...
0
by: dfirka | last post by:
Dear Everyone, Using a RichTextBox I need to replace text based on certain RTF codes found into the RTF string I look for certain embedded (hidden) information using: int i =...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.