Submatches in RegExp from LotusScript

As previously described you can use the Visual Basic Script RegExp component for regular expression matching on Windows. The component supports backreferencing and submatches which makes it easy to extract the results from pattern matching from the text. No more Instr’ing and Mid’ing to extract the information.

The below example shows you how to extract the id from a URL with an id-parameter. The output from the example will be two messageboxes stating:

  • We matched: http://www.example.com?id=123
  • Submatch 1: 1234

Sub Initialize
   'declarations
   Dim regexp As Variant
   Dim rc As Integer
   Dim text As String
   Dim submatch_count As Integer

   'set text
   text = |This is a random link http://www.example.com?id=1234 where we want to extract the id.|

   'create object
   Set regexp = CreateObject("VBScript.RegExp")

   'make pattern matching case insensitive
   regexp.IgnoreCase = True

   'set pattern
   regexp.Pattern = |http://.*?id=([d]*)|

   'test pattern
   Dim matches As Variant
   Set matches = regexp.Execute(text)
   Forall m In matches
      Msgbox "We matched: " + m.Value
      submatch_count = 1
      Forall submatch In m.Submatches
         Msgbox "Submatch " & submatch_count & ": " & submatch
         submatch_count = submatch_count + 1
      End Forall
   End Forall

End Sub

LotusScript.doc article draft is going back to The VIEW

I sent the article draft back to my editor at The VIEW yesterday and I must admit I was a little surprised as to the number of corrections she had made and that I had to look at. I ended up writing quite a lot of new content both clarifying existing points and making new ones.

It will be exciting to hear her thoughts on the added content.

LotusScript.doc release candidate 2

Release candidate 2 is just about to be released. The release contains a number of big improvements which include support for %INCLUDE files (also if nested), support for Page design elements and support for the Shared Actions design element.

Refer to to the changelog below for details on all improvements and bug fixes.

Thanks to all submitting comments, bug reports etc.

CHANGELOG – Release candidate 2

Fixes

  • Change how a REM-section is recognized to avoid problems with TAB-characters etc. efter the %REM / %END REM (Lukas Martin).
  • Added design element “namespace” handling to avoid generating the same key for different design elements with the same name (e.g. a form and an agent). (Chad Schelfhout)
  • Fix problem with page titles and generating four html documents per form, view, agent and script library.
  • Fix issue where name of function contained the returntype as well when the function didn’t contain any parentesis’ (e.g. Public Function MyFunction As Boolean)
  • Properly handle arguments to class properties (James White).

Improvements

  • Show known sub-classes for a particular class in the documentation.
  • Show icon in view for Configuration documents included in background run.
  • Provide action to go to the Documentation Index on the web.
  • Sort list of design elements alphabetically when selecting subset of design elements in Configuration document (Torben Bang).
  • Improved @-parameter parsing (tab/spaces)
  • Add support for @author parameter
  • Add support for Page design element.
  • Add support for Shared Actions design element.
  • Support for %INCLUDE files incl. nested %INCLUDE files (James White).

Known sub-classes in LotusScript.doc

When I wrote that I wouldn’t be adding more features before the release I must have been dreaming… I just couldn’t resist adding code that make it possible to see the known sub-classes of a particular class when browsing the documentation.

This makes it much easier to navigate to the sub-classes of an “interface-style” super-class as shown above where “SaveDecorator” is actually just describing the interface for the “NoAttachmentsSaveDecorator”- and “ReferencesSaveDecorator”-classes.

All this information in just 10 lines of added code – I love objects!!

LotusScript.doc Release Candidate 1

I just shot of an e-mail with LotusScript.doc release candidate 1 to the “beta” testers a few moments ago. This will hopefully be the last release for general release – changelog below.

Fixes

  • Make sure code isn’t parsed inside %REM-sections to avoid parse errors due to invalid code inside %REM-sections (Julian Buss).
  • Make sure the implicit datatype of Variant for arguments is set if an argument to a sub or function doesn’t have a datatype implicitly specified.
  • Fix issue with return type in functions having an array as an argument.

Improvements

  • Move all constants into “CLASS: LsDocConstants” script library (Alain Romedenne).
  • Make it possible to write the documentation block inside the function or sub if the function or sub is not inside a class. This allows you to keep the comment with the function or sub when copy/pasting code (Thomas Dufner).
  • Added sorting of method/function/property names in class detail pages.
  • Updated documentation.
  • Performance improvements when generating documentation in the background on the server.
  • Support for only outputting documented types (classes, subs, functions) in HTML documentation.
  • Support for ignoring private members when outputting the documentation.

I know there are some outstanding feature requests but I would rather get the tool out now than keep adding new features. I hope for your understanding.

Implementing a Bag in LotusScript

A Bag is a collection that keeps track of the number of times each element occurs in the collection. The name was inspired by the Bag implementation from the Apache Jakarta Commons Collections.

Please note that this is a quick implementation and it only handles simple datatypes – no support for objects at present.

The code is of cause documented using LotusScript.doc… 🙂

'/**
' * Implementation of a bag that is a collection that keeps track of the
' * number of times an element occurs in a collection.
' */
Public Class Bag
   'declarations
   Private pElements As Vector
   Private pElementCount List As Integer

   '/**
   ' * Constructor.
   ' */
   Public Sub New()
      Set Me.pElements = New Vector()
   End Sub

   '/**
   ' * Adds an element to the bag.
   ' * @param e The element to add.
   ' */
   Public Sub AddElement(e As Variant)
      'declarations
      Dim hash_e As Variant

      'add the element to the vector
      Call Me.pElements.AddElement(e)

      'do we have a count for this already
      If Not Iselement(Me.pElementCount(e)) Then
         'we do not have a count
         Me.pElementCount(e) = 1
      Else
         Me.pElementCount(e) = Me.pElementCount(e) + 1
      End If
   End Sub

   '/**
   ' * Get a count of the number of times an element occurs in the bag.
   ' *
   ' * @param e The element for look for.
   ' * @return Count of the times the element occurs (0 if it doesn't occur)
   ' */
   Public Function GetCount(e As Variant) As Long
      'declarations
      Dim hash_e As Variant
      If Not Iselement(Me.pElementCount(e)) Then
         GetCount = 0
      Else
         GetCount = Me.pElementCount(e)
      End If
   End Function

   '/**
   ' * Returns an array of the unique elements added.
   ' *
   ' * @return Array of unique elements added.
   ' */
   Public Function GetUnique() As Variant
      Dim v() As Variant
      Dim i As Integer
      Forall k In Me.pElementCount
         Redim Preserve v(i)
         v(i) = Listtag(k)
         i = i + 1
      End Forall
      GetUnique = v
   End Function

End Class

Small fix to Johans Vector class

Small fix to the removeElementAt(Integer) method – changes in bold.

Public Function removeElementAt(index As Integer)
   If index >= Me.size() Then Error 2000, "Array index [" & index & "] out of bounds [" & size & "]"
   Dim members As Variant
   Dim i As Integer
   Dim j As Integer
   Redim members(Me.size())
   j=0
   For i = 0 To Me.size-1
      If (i  index) And (Not j > Me.size()) Then
         If Isobject(array(i)) Then
            Set members(j) = array(i)
         Else
            members(j) = array(i)
         End If
         j = j + 1
      End If
   Next i
   elementLength = elementLength - 1
   array = members
End Function