Date: prev next · Thread: first prev next last
2014 Archives by date, by thread · List index


I have some cells that contain data like: (IBM) Ibm corporation.

I need to extract the stock symbol ie IBM. I thought I could use regex to get (IBM) and then strip the parens. So far I have been uable to do so. Usually I can search and find examples of code I can study and modify to suit my needs, but regex examples for calc seem to be few and far between.

I wonder if someone could point me to some good calc regex examples or take a look at the test code below that I have been experimenting with and tell me what I am doing wrong.

Sub getMktValue()
  'Main sub
  Dim oDoc as Object
  Dim oSheet as Object
  Dim oCalcCtrl as Object
  Dim oCell as Object
  Dim oCursor as Object
  Dim oRange as Object
  Dim myRegex as Object
  Dim found as Object
  Dim cellLoc as Object

  oDoc = ThisComponent
  'oSheet = ThisComponent.Sheets.getByName("Income")
  oSheet = oDoc.Sheets.getByName("Income")
  oRange = oSheet.getCellRangeByName("Stocks")
  numRows = oRange.Rows.getCount()

  'regex test code
  cellLoc = oSheet.getCellByPosition(0, 1)
  stk = cellLoc.String()
  myRegex =cellLoc.createSearchDescriptor()
  myRegex.SearchString = "\([A-Z]\)"
  myRegex.SearchRegularExpression = True
  found = cellLoc.findFirst(myRegex)


  'MsgBox found

End Sub

This code as is runs with out error, but if I uncomment MsgBox found I get a "object variable not set" error.

Thanks,  Jim


--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.