« March 2005 Search Hits | Main| Remembering Todd Gunn »

Class StringList

QuickImage Category Show-n-Tell Thursday

In today's post, Spanky's Place interviews Devin Olson about his current project.

SP: So tell us Devin, what are you up to?
DO: I've been attempting to port some more LotusScript code into VBA.

SP: Interesting. So, how is it going?
DO: @$%&*$!!!

SP: So it's not going well?
DO: Actually, it is going much better that could be expected. The two languages share a common root, and have almost identical syntax. The problem is that LotusScript has evolved a bit more than VBA, and has a richer object model.

SP: You mean that LotusScript is better than VBA?
DO: I wouldn't say better. The languages themselves are almost indistinguishable. In fact, porting from VBA to LotusScript is usually nothing more than a simple cut-and-paste operation. Going the other way, from LotusScript to VBA, can be more of an ordeal.

SP: And why is this?
DO: First and foremost, the Visual Studio IDE is #$$$!! &**^%# frustrating ^^*#$*&*@ hard to work with ^^@#%#* garbage %%@*#$, and usually takes quite a bit of time for a Notes developer to get comfortable with.

SP: OK, once we get past the IDE, are there any other problems?
DO: Yes, but these are normally due to differences in the object model of the two languages. Some things we take for granted and have come to rely on in LotusScript simply don't exist in VBA, and must be re-created or emulated in that environment.

SP: Can you give us an example?
DO: Sure thing.

See if you can figure out what this little beasty is for. I had to put this together just yesterday. Note - it uses my "Utilities" library, which I'm not including in this post. The specific subroutine is incValue, which increments a value. Anyway, enjoy the code:

'class_StringList:

' Option Public INTENTIONALLY REMOVED
Option Explicit
Use
"Utilities"


Public Class StringList
%REM
     This class is 256 element array of strings.
     The properties and methods allow easy navigation of the array.
%END REM
     
     
     Private bool_Initialized As Boolean
     Private intElements As Integer
     Private byteCurrentPos As Byte
     Private byteUbound As Byte
     Private varElements() As String
     
     
     ' PUBLIC PROPERTIES
     Public Property Get HasElements As Boolean
          HasElements = (intElements% > 0)
     End Property ' Get HasElements
     
     Public Property Get ElementCount As Integer
          ElementCount% = intElements%
     End Property ' Get ElementCount
     
     Public Property Get CurrentElementNumber As Integer
          CurrentElementNumber% = Cint(byteCurrentPos) + 1
     End Property ' CurrentElementNumber
     
     
     ' PUBLIC METHODS
     Public Sub New
          Call Initialize_Class
     End Sub ' New
     
     
     Public Function AddElement (strSource As String) As Boolean
      ' Returns True if the element is added to the StringList, returns False otherwise.
     
          On Error Goto ErrorTrap
     
      If (intElements% < 256) Then
           If (intElements% <> 0) Then incValue byteUbound, 1
               varElements(byteUbound) = strSource$
               byteCurrentPos = byteUbound
               incValue intElements%, 1
               AddElement = True
      Else
               AddElement = False
      End If ' (intElements% < 256)
     
ExitPoint:
          Exit Function
ErrorTrap:
          AddElement = False
          Resume ExitPoint
     End Function ' AddElement
     
     
     Public Function GetFirst As String
      ' returns the first element of the StringList
          GetFirst = varElements(0)
          byteCurrentPos = 0
     End Function ' GetFirst
     
     Public Function GetNext As String
      ' returns the next elment (based on the current position) of the StringList
      If (byteCurrentPos < byteUbound) Then
               incValue byteCurrentPos, 1
               GetNext = varElements(byteCurrentPos)
      Else
               GetNext = ""
      End If ' (byteCurrentPos < byteUbound)
     End Function ' GetNext
     
     Public Function GetPrevious As String
      ' returns the previous elment (based on the current position) of the StringList
      If (byteCurrentPos > 0) Then
               incValue byteCurrentPos, -1
               GetPrevious = varElements(byteCurrentPos)
      Else
               GetPrevious = ""
      End If ' (byteCurrentPos > 0)
     End Function ' GetPrevious
     
     Public Function GetLast As String
      ' returns the last element of the StringList
          byteCurrentPos = byteUbound
          GetLast = varElements(byteCurrentPos)
     End Function ' GetLast
     
     Public Function PopLast As String
      ' This function is similar to GetLast,
      ' except it also removes the last element from the StringList
          PopLast = varElements(byteUbound)
      If (intElements% > 0) Then
               varElements(byteUbound) = ""
               incValue intElements%, -1
      End If ' (intElements% > 0)
     
      If byteUbound > 0 Then incValue byteUbound, -1
          byteCurrentPos = byteUbound
     End Function ' PopLast
     
     
     Public Function PopFirst As String
      ' This function is similar to GetFirst,
      ' except it also removes the first element from the StringList and then reorders the StringList
      If (intElements% > 0) Then
               PopFirst = varElements(0)
           If (byteUbound > 0) Then
                    For byteCurrentPos = 1 To byteUbound
                         varElements(byteCurrentPos -1) = varElements(byteCurrentPos)
                Next ' byteCurrentPos
                    varElements(byteUbound) = ""
                    incValue byteUbound, -1
           Else
                    varElements(0) = ""
           End If ' (byteUbound > 0)
          
               incValue intElements%, -1
          
      Else
               PopFirst = ""
      End If ' (intElements% > 0)
     
          byteCurrentPos = 0
     
     End Function ' PopFirst
     
     
     Public Sub Delete
      If bool_Initialized Then
               Redim varElements(0) As String
               varElements(0) = ""
      End If ' bool_Initialized
     
          intElements% = 0
          byteCurrentPos = 0
          byteUbound = 0
          bool_Initialized = False
     End Sub ' Delete
     
     
     ' PRIVATE METHODS
     Private Sub Initialize_Class
     
          Redim varElements(0 To 255) As String
     
          intElements% = 0
          byteCurrentPos = 0
          byteUbound = 0
          bool_Initialized = True
     End Sub ' Initialize_Class
     
End Class ' StringList

-Devin

Comments

Gravatar Image1 - Oh how I love Lists in LotusScript.

Gravatar Image2 - So do I.

I think lists are probably one of the most under-utilized and under-recognized "things" within the whole of LotusScript.

-Devin.

Search

Wowsers! A Tag Cloud!

Links

MiscLinks