Guest User

Untitled

a guest
Feb 8th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub SimpleSearchExample
  2.  parseWordsFromCurrentDoc()
  3. End Sub
  4.  
  5. Public Function parseWordsFromCurrentDoc()
  6.   Dim vDescriptor, vFound
  7.   vDescriptor = ThisComponent.createSearchDescriptor()
  8.    
  9.   With vDescriptor
  10.     .SearchString = "\w+"
  11.     .SearchRegularExpression = true
  12.   End With
  13.  
  14.   vFound = ThisComponent.findFirst(vDescriptor)
  15.   proccessVFound(vFound)
  16.  
  17.   Do While Not IsNull(vFound)
  18.     vFound = ThisComponent.findNext(vFound.End, vDescriptor)
  19.     proccessVFound(vFound)
  20.   Loop  
  21. End Function
  22.  
  23.  
  24. Public Function wordCount(wordToSearch) As Integer
  25.   Dim vDescriptor, vFound
  26.   vDescriptor = ThisComponent.createSearchDescriptor()
  27.  
  28.   Dim count As Integer  
  29.   With vDescriptor
  30.     .SearchString = wordToSearch
  31.     .SearchWords = true
  32.     .SearchCaseSensitive = true
  33.   End With
  34.   vFound = ThisComponent.findFirst(vDescriptor)
  35.   count = 0
  36.   Do While Not IsNull(vFound)
  37.     count = count + 1
  38.     vFound = ThisComponent.findNext(vFound.End, vDescriptor)
  39.   Loop
  40.   wordCount = count
  41. End Function
  42.  
  43. Public Function proccessVFound(vFound)
  44.     Dim count As Integer
  45.     Dim word As String
  46.     If Not IsNull(vFound) Then
  47.         word = vFound.String
  48.         count = wordCount(word)
  49.         exportResultToCalc(word,count)
  50.     End If
  51. End Function
  52.  
  53. 'export to OpenOffice.Calc
  54. Public Function exportResultToCalc(word,count)
  55. 'Fake!!!!!!!!!!!!
  56. 'But work :)
  57. MsgBox "word="+word+"; count="+count
  58. 'to be continued....
  59. End Function
Add Comment
Please, Sign In to add comment