• Browse Blogs
  • My Blog
  • My Updates

+Tags Get help with tags?

  • View as cloud  | list

+ Similar Blogs

photo

Lotus Nut

111 Entries |  Chris Whisonant
Updated 
RatingsRatings 23     CommentsComments 157
photo

Big Mutant Bl...

49 Entries |  Michael Smelser
Updated 
RatingsRatings 1     CommentsComments 49
photo

Yellow is the...

72 Entries |  Tim Tripcony
Updated 
RatingsRatings 2     CommentsComments 34
photo

Patrick Picar...

62 Entries |  Patrick Picard
Updated 
RatingsRatings 2     CommentsComments 112
photo

off the Hook ...

53 Entries |  Scott Hooks
Updated 
RatingsRatings 6     CommentsComments 81

+ Blog Authors  

All entries tagged with lotusscript

1 - 10 of 10
  • Previous
  • Next
  • Page   1

ProgressBar class for Lotusscript

Karl-Henry Martinsson |   | Tags:  lotusscript code | Comments (4)  |  Visits (740)

Brian Moore wrote about the problem with users thinking Notes applications are slow, due to no visible feedback:
"People seem to be totally happy at letting something take bleeding ages just so long as there is a little moving object to distract them from the clock."

This is very true, and I addressed this in one of my applications a while back by implementing a progress bar.
Suddenly, when the users got feedback on what was happening, all complaints about it being slow stopped, despite it taking the same amount of time...

I built a progress bar class. Here it is, as well as a small code sample showing how to call it. Note that this is a Win32 only solution.

' ***** Declarations for (undocumented) progress bar in Notes ***** Private Const NPB_TWOLINE% = 1 Private Const NPB_STATUSBAR% = 32 Declare Private Function NEMProgressBegin Lib "nnotesws.dll" ( Byval wFlags As Integer ) As Long Declare Private Sub NEMProgressDeltaPos Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwIncrement As Long ) Declare Private Sub NEMProgressEnd Lib "nnotesws.dll" ( Byval hwnd As Long ) Declare Private Sub NEMProgressSetBarPos Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwPos As Long) Declare Private Sub NEMProgressSetBarRange Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwMax As Long ) Declare Private Sub NEMProgressSetText Lib "nnotesws.dll" ( Byval hwnd As Long, Byval pcszLine1 As String, Byval pcszLine2 As String ) Class ProgressBar Private hidden As Integer Private hwnd As Long Private value As Long Private title As String Private textline1 As String Private textline2 As String Private maxvalue As Long Public Sub New(range As Long, initialtitle As String) Dim session As New NotesSession maxvalue = Clng(range) title = initialtitle textline1 = "" textline2 = "" ' Check if code is running on server (scheduled agent) Íf session.IsOnServer Then hidden=True Else hidden=False End If If hidden = True Then Exit Sub End If hwnd = NEMProgressBegin(NPB_TWOLINE) Call SetRange(maxvalue) NemProgressSetText hwnd, title, textline1 & Chr$(13) & textline2 End Sub Sub Increase() If hidden = True Then Exit Sub End If If hwnd <> 0 Then If value < maxvalue Then value = value + 1 NEMProgressSetBarPos hwnd, value End If End If End Sub Sub Decrease() If hidden = True Then Exit Sub End If If hwnd <> 0 Then If value > 0 Then value = value - 1 NEMProgressSetBarPos hwnd, value End If End If End Sub Sub Close If hidden = True Then Exit Sub End If If hwnd <> 0 Then NEMProgressEnd hwnd hwnd = 0 title = "" value = 0 End If End Sub Sub SetRange(value As Long) If hidden = True Then Exit Sub End If If hwnd <> 0 Then maxvalue = value NEMProgressSetBarRange hwnd, maxvalue End If End Sub Sub SetValue(value As Long) If hidden = True Then Exit Sub End If If hwnd <> 0 Then NEMProgressSetBarPos hwnd, value End If End Sub Sub SetText(message As String) If textline2="" Then Call PrintText() End If If hidden = True Then Exit Sub End If If hwnd <> 0 Then textline1 = message NEMProgressSetText hwnd, title, textline1 & Chr$(13) & textline2 End If End Sub Sub SetText2(message As String) Call PrintText() If hidden = True Then Exit Sub End If If hwnd <> 0 Then textline2 = message NEMProgressSetText hwnd, title, textline1 & Chr$(13) & textline2 End If End Sub Function GetText() As String GetText = textline1 End Function Function GetText2() As String GetText2 = textline2 End Function Sub PrintText() Dim text As String If hidden = True Then text = textline1 If textline2<>"" Then text = text & " - " & textline2 End If Print text End If End Sub Function Show() As String hidden = False hwnd = NEMProgressBegin(NPB_TWOLINE) Call SetRange(maxvalue) NemProgressSetText hwnd, title, textline1 & Chr$(13) & textline2 End Function Function Hide() As String hidden = True If hwnd <> 0 Then NEMProgressEnd hwnd hwnd = 0 End If End Function End Class
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.


Here is some sample code:

units = GetNumberOfUnits() Set pbar = New ProgressBar(Clng(units+1),"Loading data from backend server...") Call pbar.Show() For i = 1 to units Call pbar.Increase() Call pbar.SetText("Loading coverage for unit " & i & "...") set vehicle = New CoverageData(i) ' Get vehicle coverage Call pbar.SetText2(vehicle.year & " " & Fulltrim(vehicle.name) & " - Coverage " & vehicle.cvgcode) Next Call pbar.Increase() Call pbar.SetText("Finishing processing.") Call pbar.SetText2("Please wait...") ' Do some more stuff here Call pbar.Close()
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

More fun with lists

Karl-Henry Martinsson |   | Tags:  code lotusscript | Comments (0)  |  Visits (414)

After Kathy Brown wrote about lists earlier today, I thought I would share another example of how they can be used. Back in April I shared some code showing how to get latitude and longitude for an address, by calling Google's GeoCode REST service.
Today I will show how easy it is to use that class together with a list...

First, let's revisit the GeoCode class. I made some minor modifications, so I will post the latest version here:

Class GeoData Private GeoString As String Public street As String Public city As String Public zip As String Public state As String Public latitude As String Public longitude As String Public Sub New(streetStr As String, cityStr As String, stateStr As String, zipStr As String) Dim httpObject As Variant Dim mapsKey As String Dim mapsURL As String Dim address As String Dim retries As Integer Dim httpURL As String Dim returncode As String Dim coordinates As String Dim ret As Integer Dim xmladdress As String Dim addarray As Variant retries = 0 Set httpObject = CreateObject("MSXML2.ServerXMLHTTP") mapsKey = "your_googleAPI_key" mapsUrl = "http://maps.google.com/maps/geo?q=" address = streetStr & ", " & cityStr & ", " & stateStr & " " & zipStr httpURL = mapsURL & address & "&output=xml&key=" & mapsKey ' Use output=CSV for CVS file Do If retries>1 Then Sleep 1 ' After the two first calls, introduce a 1 second delay betwen each additional call End If retries = retries + 1 Call httpObject.open("GET", httpURL, False) Call httpObject.send() GeoString = Left$(httpObject.responseText,16000) returncode = GetGeoValue("code") If retries >= 10 Then returncode = "500" ' Fake other failure after 10 attempts End If Loop Until returncode <> "620" If returncode = "200" Then coordinates = GetGeoValue("coordinates") latitude = Left$(coordinates, Instr(coordinates,",")-1) longitude = Mid$(coordinates, Len(latitude)+2, Instr(Len(latitude)+2,coordinates,",")-Len(latitude)-2) street =GetGeoValue("ThoroughfareName") zip = GetGeoValue("PostalCodeNumber") city = GetGeoValue("LocalityName") state = GetGeoValue("AdministrativeAreaName") xmladdress = GetGeoValue("address") If city = "" Then If state <> "" Then addarray = R5split(xmladdress,", ") city = addarray(1) zip = Right$(addarray(2),5) End If End If If Ucase(state)<>Ucase(stateStr) Then ' Different state? ret = Msgbox("The address returned seems to be very different" & Chr$(13) & _ "from the one submitted." & Chr$(13) & _ "The address returned is:" & Chr$(13) & Chr$(13) & _ street & Chr$(13) & city & ", " & state & " " & zip & Chr$(13) & Chr$(13) & _ "Do you want to use this address?",4+32,"WARNING") If ret = 7 Then street = streetStr zip = zipStr city = cityStr state = stateStr End If End If If street = "" Then Msgbox "The street address could not be verified." & Chr$(13) & _ "Existing value will be saved." & Chr$(13) & _ "Please verify that address is correct.",,"Street Not Verified" street = streetStr End If If city = "" Then Msgbox "The city could not be verified." & Chr$(13) & _ "Existing value will be saved." & Chr$(13) & _ "Please verify that address is correct.",,"City Not Verified" city = cityStr End If Else If returncode = "602" Then Msgbox "No corresponding geographic location found"_ ,,"Google GeoCode Error 602" Elseif returncode = "603" Then Msgbox "The geocode cannot be returned due to legal or contractual reasons." _ ,,"Google GeoCode Error 602" End If ' Return original value to avoid overwriting... street = streetStr zip = zipStr city = cityStr state = stateStr End If End Sub Public Function Accuracy() As Integer Dim startpos As Long Dim endpos As Long If IsValid = False Then Accuracy = 0 Exit Function End If startpos = Instr(Lcase(GeoString),|accuracy="|) + 10 endpos = Instr(startpos, Lcase(GeoString), |"|) If endpos < startpos Then Accuracy = 0 Else Accuracy = Cint(Fulltrim(Mid$(GeoString,startpos, endpos - startpos))) End If End Function Public Function HasAddInfo(address As String) As Integer If Instr(Lcase(address),"apt")>0 Then HasAddInfo = True Elseif Instr(Lcase(address),"apartment ")>0 Then HasAddInfo = True Elseif Instr(Lcase(address),"suite ")>0 Then HasAddInfo = True Elseif Instr(Lcase(address),"ste ")>0 Then HasAddInfo = True Elseif Instr(Lcase(address)," #")>0 Then HasAddInfo = True Elseif Instr(Lcase(address),", ")>0 Then HasAddInfo = True Else HasAddInfo = False End If End Function Public Function Compare(str1 As String, str2 As String) As Integer End Function Public Function IsValid() As Integer If GeoString = "" Then IsValid = False Else IsValid = True End If End Function Public Function GetGeoValue(tag As String) As String Dim startpos As Long Dim endpos As Long Dim tempstring As String If GeoString = "" Then GetGeoValue = "" Exit Function End If startpos = Instr(Lcase(GeoString),"<" & Lcase(tag) & ">") + Len(tag) endpos = Instr(startpos, Lcase(GeoString), "</"+Lcase(tag) & ">") If endpos < startpos Then GetGeoValue = "" Else tempstring = Fulltrim(Mid$(GeoString,startpos+2, endpos - startpos - 2)) GetGeoValue = Fulltrim(R5strReplace(tempstring,"&amp;","&")) End If End Function Private Function R5strReplace(mystring As String, search As String, replacewith As String) As String Dim source As String source = mystring While Instr(source, search) > 0 source = Left$(source, Instr(source, search) - 1) + replacewith + _ Right$(source, Len(source) - Instr(source, search) - Len(search) + 1) Wend R5strReplace = source End Function Private Function R5split(strSource As String, strItemDelim As String) As Variant Dim astrReturn() As String ' The array to return Dim intElement As Integer ' The array element currently being set Dim z_intItemCount As Integer ' The total number of elements for the array Dim z_intStartOfItem As Integer ' The start position of the item in the source string. Dim z_intEndOfItem As Integer ' The end position of the item in the source string. Dim z_strCurItem As String ' The currently parsed item Dim z_strRemaining As String ' The remaining string to cycle through Dim z_strStartOfItemBack As String ' The rest of the string, from the start of the item on back. z_strRemaining = strSource ' Cycle through the source string and get a count of elements: While (Not z_strRemaining = "") z_intStartOfItem = Instr(1, z_strRemaining, strItemDelim) If (z_intStartOfItem <> 0) Then z_intItemCount = z_intItemCount + 1 z_strRemaining = Mid(z_strRemaining, z_intStartOfItem + Len(strItemDelim), Len(z_strRemaining)) Else z_intItemCount = z_intItemCount + 1 z_strRemaining = "" End If Wend ' Size the return array so that it can hold all of the elements: Redim astrReturn(z_intItemCount - 1) ' Reset the holder to the value of the source string: z_strRemaining = strSource ' Cycle through the source list, parsing the string into individual array elements: While (Not z_strRemaining = "") For intElement = 0 To Ubound(astrReturn) ' Find the end of the current element: z_intEndOfItem = Instr(1, z_strRemaining, strItemDelim) ' If there is still an item delimiter in the string, parse ' out the item, otherwise assume the remaining text is the ' last item: If (z_intEndOfItem <> 0) Then z_strCurItem = Mid(z_strRemaining, 1, z_intEndOfItem - 1) astrReturn(intElement) = z_strCurItem z_strRemaining = Mid(z_strRemaining, z_intEndOfItem + Len(strItemDelim), _ Len(z_strRemaining)) Else astrReturn(intElement) = z_strRemaining z_strRemaining = "" End If Next Wend ' Return the split array to the caller: R5split = astrReturn End Function End Class
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

Below is a simple code sample that will read all person documents from the NAB, get address information for each person, create a list of GeoData objects, then loop through the list and retrieve data out of it.
Of course it could have been done all in the first loop, but I am splitting it up for demonstration purposes.

Sub ProcessDocs Dim db As New NotesDatabase("dsCorp/Deep-South","names.nsf") Dim view As NotesView Dim doc As NotesDocument Dim geodata As GeoData Dim street As String Dim city As String Dim state As String Dim zip As String Dim uind As strring ' Loop though all person documents Set view = db.GetView("People") Set doc = view.GetFirstDocument() Do While doc Is Not Nothing ' Read address from person documents street = doc.OfficeStreetAddress(0) city = doc.OfficeCity(0) state = doc.OfficeState(0) zip = doc.OfficeZIP(0) If street<>"" Then ' Make sure we have an address unid = doc.UniversalID ' Person document unid, used as list tag ' Create a new list item, with unid as list tag and a GeoData object stored Set geodata(unid) = New GeoData(street, city, state, zip) End If Set doc = view.GetNextDocument(doc) Loop ' Now we will look through the list and get docs again Forall g In geodata ' Get the person document again based on list tag Set doc = db.GetDocumentByUNID( Listtag(g) ) ' Write latitude and longitude to person document doc.OfficeLatitude = g.Latitude doc.OfficeLongitude = g.Longitude Call doc.Save(True,True) End Forall End Sub
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

Simple Mail Notification Class

Karl-Henry Martinsson |   | Tags:  code lotusscript | Comments (0)  |  Visits (391)
I have a function I wrote way back to generate mail notification out of my program. But in many cases it had to be modified for each use. Yesterday I decided to write simple class instead, and here is the result. I will post it at OpenNTF.org soon as well.

This is how you use the class:

Set mailnotification = New MailNotification()
mailnotification.SendTo="texasswede@gmail.com"
mailnotification.Subject = "Test email fron Notes"
mailnotification.Principal = "System X "
Call mailnotification.body.AppendText( "This is some text in the body field. " )
Call mailnotification.body.AppendText( "And some more." )
Call mailnotification.body.AddNewLine( 1 )
Call mailnotification.body.AppendText( "Docclink: " )
Call mailnotification.body.AppendDocLink( doc, "Click to open" )
Call mailnotification.body.AddNewLine( 2 )
Call mailnotification.Send()

Easy, huh?
And here is the class itself. I store it in a script library called Class.MailNotification... Enjoy!

Class MailNotification Public maildoc As NotesDocument Public body As NotesRichTextItem Public subject As String Public sendto As String Public copyto As String Public bccto As String Public principal As String Public Sub New() Dim session As New NotesSession Set maildoc = New NotesDocument(session.CurrentDatabase) Call maildoc.ReplaceItemValue("Form","Memo") Set body = New NotesRichTextItem(maildoc,"Body") subject = "" sendto = "" copyto = "" bccto = "" principal = "" End Sub Public Sub Send() If subject<>"" Then maildoc.Subject = subject End If If sendto<>"" Then maildoc.SendTo = sendto End If If copyto<>"" Then maildoc.CopyTo = copyto End If If bccto<>"" Then maildoc.BlindCopyTo= bccto End If If principal<>"" Then maildoc.Principal = principal End If Call maildoc.Send(True) End Sub End Class
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

Get latitude and longitude for an address

Karl-Henry Martinsson |   | Tags:  lotusscript google maps | Comments (0)  |  Visits (818)

Recently my boss asked me to come up with a way to show certain information on a map of some kind, and after doing some research I decided to simply create a KML file and use Google Earth. In order to create the KML file, I needed latitude and longitude of each address I was going to display. I found a couple of different free services, and I decided to use the one from Google.

The Google Geocode service is using a REST API, so it was easy to write some code to send address and retrieve XML with (among other things) latitude and longitude. An additional benefit is that the address get check and modified, so if the ZIP is off, or the name of the street is not "Street" but "Drive", the correct values get returned.

You need to sign up to get your own key from Google, but it is free. 

Today I decided to write a small class to do this lookup, so now I can add this to any program I write. Below is the code for the script library, as well as a small code sample how to call it. Enjoy!

Dim geodata As GeoData Set geodata = New GeoData("6363 North State Highway 161", "Irving", "tx", "") If geodata.IsValid Then Msgbox geodata.Street & Chr$(13) & geodata.City & ", " & geodata.State & " " & geodata.ZIP,, _
"Accuracy = " & geodata.Accuracy Msgbox "Lat: " & geodata.Latitude & " Longitude: " & geodata.Longitude End If
Class GeoData Private GeoString As String Public street As String Public city As String Public zip As String Public state As String Public latitude As String Public longitude As String Public Sub New(streetStr As String, cityStr As String, stateStr As String, zipStr As String) Dim httpObject As Variant Dim mapsKey As String Dim mapsURL As String Dim address As String Dim retries As Integer Dim httpURL As String Dim returncode As String Dim coordinates As String Set httpObject = CreateObject("MSXML2.ServerXMLHTTP") mapsKey = "your key goes here" mapsUrl = "http://maps.google.com/maps/geo?q=" address = streetStr & ", " & cityStr & ", " & stateStr & " " & zipStr httpURL = mapsURL & address & "&output=xml&key=" & mapsKey ' Use output=CSV for CSV file Do retries = retries + 1 Call httpObject.open("GET", httpURL, False) Call httpObject.send() GeoString = Left$(httpObject.responseText,16000) returncode = GetGeoValue("code") If retries >= 10 Then returncode = "500" ' Fake other failure after 10 attempts End If Loop Until returncode <> "620" If returncode = "200" Then coordinates = GetGeoValue("coordinates") latitude = Left$(coordinates, Instr(coordinates,",")-1) longitude = Mid$(coordinates, Len(latitude)+2, Instr(Len(latitude)+2, _
coordinates,",")-Len(latitude)-2) street =GetGeoValue("ThoroughfareName") zip = GetGeoValue("PostalCodeNumber") city = GetGeoValue("LocalityName") state = GetGeoValue("AdministrativeAreaName") Msgbox GeoString Else GeoString = "" End If End Sub Public Function Accuracy() As Integer Dim startpos As Long Dim endpos As Long If IsValid = False Then Accuracy = 0 Exit Function End If startpos = Instr(Lcase(GeoString),|accuracy="|) + 10 endpos = Instr(startpos, Lcase(GeoString), |"|) If endpos < startpos Then Accuracy = 0 Else Accuracy = Cint(Fulltrim(Mid$(GeoString,startpos, endpos - startpos))) End If End Function Public Function IsValid() As Integer If GeoString = "" Then IsValid = False Else IsValid = True End If End Function Public Function GetGeoValue(tag As String) As String Dim startpos As Long Dim endpos As Long Dim tempstring As String If GeoString = "" Then GetGeoValue = "" Exit Function End If startpos = Instr(Lcase(GeoString),"<" & Lcase(tag) & ">") + Len(tag) endpos = Instr(startpos, Lcase(GeoString), "</"+Lcase(tag) & ">") If endpos < startpos Then GetGeoValue = "" Else tempstring = Fulltrim(Mid$(GeoString,startpos+2, endpos - startpos - 2)) GetGeoValue = Fulltrim(R5strReplace(tempstring,"&amp;","&")) End If End Function Private Function R5strReplace(mystring As String, search As String, replace As String) As String Dim source As String source = mystring While Instr(source, search) > 0 source = Left$(source, Instr(source, search) - 1) + replace + _
Right$(source, Len(source) - Instr(source, search) - Len(search) + 1) Wend R5strReplace = source End Function End Class
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

No RatingsRatings 0

Lotusscript to rename downloaded files

Karl-Henry Martinsson |   | Tags:  downloads code lotusscript | Comments (1)  |  Visits (896)
Duffbert and Jim Casale both blogged about the cryptic names on downloaded files from the IBM Passport Advantage site. Jim's Excel macro inspired me to write something in Lotusscript (I don't even have Excel on my home computers anymore, I am only using Symphony now).

Below is my Lotusscript code. Note that I have not been able to test the actual renaming part, since I am at the office and I have all the files downloaded at home. But the parsing part works. You may want to either modify the location of dlmgr.pro, or even write some code to let the user select the file to process. But I just made a quick-and-dirty hack for now.

Update: Something went wrong earlier when I tried to post this, I got two borked entries. It seems like if I paste certain formatted text (like the code section below) into the entry, and save it while in preview/WYSIWYG mode, it breaks the entry. If I am in HTML code view, it works...
Update 2: Thanks to the guys at Lotus911, they removed the two bad entries. Also, I wanted to clarify, the code is actually copying the files and giving the copy a new name, the original files are still there. If you want to perform a move, un-comment the the line Kill fromfile.

Dim dlmgrfile As String Dim dirname As String Dim filename As String Dim filecode As String Dim filedescription As String Dim temp As String Dim newitem As Integer Dim fromfile As String Dim tofile As String dlmgrfile = "c:\dlmgr.pro" Open dlmgrfile For Input As #1 Do While Not Eof(1) Line Input #1, temp If Left$(temp,6)=".file=" Then filecode = Right$(temp,Len(temp)-6) newitem = True Elseif Left$(temp,2) = ".." Then newitem = False End If If Left$(temp,7) = "..path=" Then dirname = Right$(temp,Len(temp)-7) End If If Left$(temp,8)="..title=" Then filedescription = Right$(temp,Len(temp)-8) End If If Left$(temp,7)="..name=" Then filename = Right$(temp,Len(temp)-7) End If If newitem = False Then If filename<>"" Then If dirname<>"" Then If filedescription<>"" Then fromfile = dirname & "\" & filename tofile = dirname & "\" & filedescription & Right$(filename,4) Print "Copying " & fromfile & " to " & tofile Filecopy fromfile, tofile ' Kill fromfile dirname = "" filename = "" filedescription = "" filecode = "" End If End If End If End If Loop Close #1
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

Generate Excel spreadsheets using Lotusscript

Karl-Henry Martinsson |   | Tags:  lotusscript programming | Comments (1)  |  Visits (557)

 Bill Buchan just wrote about exporting data to Excel using a CSV file. There is actually a cool and surprisingly easy way to generate documents that show up in Excel as real spreadsheets, with formatting, colors, etc.

Simply create a file containing a HTML table. It may even work with multiple tables. You can use tags like <B> and <I> for bold/italic, and use the color attribute to set text color and background color. Use the colspan attribute to split a cell over multiple columns.

Save the file in Lotusscript as a regular text file, but with the extension XML XLS. Excel, as well as OpenOffice.org, will read the HTML and present as a nice spreadsheet.

No RatingsRatings 0

Simple but effective code

Karl-Henry Martinsson |   | Tags:  development lotusscript | Comments (0)  |  Visits (474)

The other day I was writing some code where I had to check a value against a list of potential values. I was importing a file as XML, and checking a number of transactions, each in their own node. If the Trans-ID tag had one of several values, the whole node was supposed to be discarded and not used.
I am sure many already use this method, but hopefully someone will learn something new.
In my example below, I am reading a field in a Notes document instead of data from an XML file, but the principle is the same:

tranType = Ucase(doc.GetItemValue("txn-type"))
If Instr("PD;DR;RP;NSFNF;RD;CRT;RCT;VCK;TPD;RCK;", tranType & ";") Then

End If

What I do is to use Instr() to check a string (the first argument) for the presence of a particular string (the second argument). To make sure I don't get any false matches, I add a semicolon to the end of the tranType as well as use the same character to separate the values in the first argument.

The Instr() function returns the position of the string found (1 or higher if found, 0 if not found). Since 0 is "False" and everything else is "True", if the tranType string is found, a value greater than 0 is returned, which is considered "True".


This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

Parse URL in Domino agent

Karl-Henry Martinsson |   | Tags:  web code_snippet programming lotusscript | Comments (3)  |  Visits (1,180)

Not Forum Friday, but Usenet Tuesday. :-)  A user in comp.groupware.lotus-notes.programmer had a question about generating Notes document remotely/in an automated way from another web application, using Perl:

 

> We have a Lotus Notes application and we would like to automate
> creating a new document or record in that application from another web
> based application.
>
> Here are the details:
> User action on web application triggers a PERL script to create a new
> record (document) in Lotus Notes (or Domino).

 

Here is my suggestion:

 

Create an agent that read the URL parameters you send to it.
Let's call the agent CreateNewDocument, and have two fields we want to fill out when the document is created. The Perl script can then call the URL like this:
 
 
The agent read the arguments and populate the corresponding fields, then save the document. I would highly recommend using a list to store the parameters, then you have a generic function you can re-use in any application.
In my article in the November/December 2006 issue of The View (starting on page 25) you have code for this.
 
Here is a class I just wrote to parse an incoming HTTP GET or POST. Put it in a script library called for example "URL.class":
 
Class URLclass
Public url As String
Private params List As String

Public Sub New()
  Dim session As New NotesSession
  Dim doc As NotesDocument
  Set doc = session.DocumentContext ' Document with all CGI variables
  ' Check if HTTP GET or POST was used...
  If Instr(doc.Query_String(0),"&") > 0 Then  ' GET was used
   url = doc.Query_String(0) 
  Elseif Instr(doc.Request_Content(0),"&") > 0 Then ' POST was used
   url = "&" & doc.Request_Content(0)
  Else          ' No parameters
   Exit Sub
  End If
End Sub

Public Function GetParams() As Variant
  Dim offset As Integer
  Dim startpos As Integer
  Dim midpos As Integer
  Dim endpos As Integer
  Dim nextpos As Integer
  Dim dataname As String
  Dim datavalue As String
  startpos = Instr(url,"&")    ' Start of first parameter
  Do While Not startpos = 0
   nextpos = Instr(startpos+1, url, "&") ' Start of next parameter
   If nextpos = 0 Then     ' We reached the end
    endpos = Len(url)+1
   Else
    endpos = nextpos
   End If
   midpos = Instr(startpos+1, url, "=") ' Position of = character
   dataname = Mid$(url,startpos+1,midpos-startpos-1)  ' Get name
   datavalue = Mid$(url,midpos+1,endpos-midpos-1)  ' Get value
   params(dataname) = datavalue   ' Add value to list
   startpos = nextpos     ' Set new start position
  Loop
  GetParams = params
End Function

End Class
 

Here is a sample agent that uses the class and print the arguments to the browser. Just expand on that code to create the document in the database:

 

Option Public
Option Declare
Use
"URL.class"
 

Sub Initialize
 Dim url As New URLclass

 Dim params As Variant
 params = url.GetParams()
 Forall x In params
   Print Listtag(x) & " = " & params(Listtag(x)) & "<br>"
 End Forall
End Sub

 

The LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

SNTT - XML importer class

Karl-Henry Martinsson |   | Tags:  lotusscript show-n-tell-thursday xml | Comments (0)  |  Visits (502)

Yes, I know it is Tuesday, but I was too busy last week for the SNTT entry...

 

At my workplace, we are in the process of purchasing and implementing a new billing system. It relies heavily on XML files, stored in the file system, for inport/export. The idea is that we export XML from our policy system to be processed by this software. The results are returned as XML files, and we are currently looking at how we can consume them and present them to the accounting department.

We are mainly looking at tools like Crystal Reports 2008.

Just for fun, I decided to write an XML importer in Lotusscript. The XML is very simple so I did not have to do any advanced parsing.
I decided to write it as a class. The class just have a few methods. One is of course New(), the only thing it does is clear the xmldata string and also clear the list of XML tags from memory.

LoadXMLData() open the specified XML file and read the text into the xmldata string, adding a linebreak after each line.

XML2List take the xmlstring, parse it and build a list of all the tags and values. Because the XML is so simple, with no multiple values or deeply nested data, I can very easily parse it using normal string operations in a Do-While loop.

The final method is called CreateNotesDocument(), it creates a new Notes document in the specified database, using the specified form. To process the sample XML file with 66 XMl entries took 0.148 seconds (according to TeamStudio Profiler).

Here is the code:

Class XMLClass
Private xmldata As String
Private xml List As String

Public Sub New()
  xmldata=""
  Erase xml
End Sub

Public Sub LoadXMLData(filename As String)
  Dim xmlline As String
  Open filename For Input As #1
  xmldata = ""
  While Not Eof(1)
   Line Input #1, xmlline
   xmldata = xmldata & xmlline & Chr$(13)
  Wend
  Close #1
End Sub

Public Sub XML2List()
  Dim tag As String
  Dim value As String
  Dim startpos As Long
  Dim endpos As Long
  Dim nextpos As Long
  Dim endtagpos As Long
 
  endpos = 1
  Do
   startpos = Instr(endpos,xmldata,"<")
   If startpos > 0 Then
    endpos = Instr(startpos,xmldata,">")
   End If
   If endpos > 0 Then
    tag = Mid$(xmldata,startpos+1,endpos-startpos-1)
    If Instr(tag,"/")=1 Then
     startpos = Instr(endpos+1,xmldata,"<")
    Else
     nextpos = Instr(endpos,xmldata,"<")
     endtagpos = Instr(endpos,xmldata,"</" & tag & ">")
     If endtagpos = nextpos Then
      value = Mid$(xmldata,endpos+1,nextpos-endpos-1)
      If Iselement(xml(tag)) = False Then
       xml(tag) = value
      End If
      endpos = Instr(nextpos,xmldata,">")
     End If
    End If   
   End If
  Loop While startpos > 0
End Sub

Public Sub CreateNotesDocument(db As NotesDatabase, form As String)
  Dim doc As NotesDocument
  Set doc = New NotesDocument(db)
  doc.Form = form
  Forall x In xml
   Call doc.ReplaceItemValue(Listtag(x),x)
  End Forall
  Call doc.Save(True,True)
End Sub
 
End Class


Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim noic As XMLclass

Set db = session.CurrentDatabase
Set noic = New XMLclass()
Call noic.LoadXMLData("c:\XSLT\NOIC-1450-01 0-2007Nov09.xml")
Call noic.XML2List()
Call noic.CreateNotesDocument(db,"NOIC")
End Sub


 

This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
No RatingsRatings 0

SNTT: Lists - the forgotten gem in Lotusscript

Karl-Henry Martinsson |   | Tags:  show-and-tell-thursday programming sntt lotusscript | Comments (2)  |  Visits (447)
OK, I know it is Friday already, but here is my Show-n-Tell-Thursday entry...

Lists are a data type that I don't think is used enough. Many Notes developers, even some that been programming in the environment for years, don't use this very powerful feature. In previous years, Bill Buchan have been talking about lists in some of his Lotussphere sessions, and when asking how many in the audience that used lists, less than 10% raised their hands.

So what are lists? They are a data type, similar to an array, but instead of using a numeric index, it uses a string as index, or tag as it is called.

This makes it easy to address items in the list, check if they exists, etc.

Here is a simple example:

Dim age List as Integer

Dim name as String

age( "karl" ) = 38

age( "erik" ) = 7

name = InputBox$( "Enter name:" )

If IsElement(age(Lcase(name))) = True Then

MsgBox name & " is " & age(lcase(name)) & " years old."

Else

MsgBox name & " does not occur in the list."

End If

This code define a list of integers, containing the age of two people. When a name is entered in the input box, IsElement is used to check if an item with that name is found in the list. If it is, the age is displayed, if not another message is displayed, saying that the name was not found.

Note that the list tag (name in this case) is case sensitive! 

To loop through a list and display all the values, use ForAll. Here is an example where we loop thorugh all the entries and display their list tags as well as the values:

Dim age List As Integer
age( "Karl" ) = 38
age( "Erik" ) = 7
Forall a In age
Msgbox Listtag(a) & " is " & a & " years old."
End Forall

Some of the things I use lists for are web agents, where I parse the URL passed for parameters, and build a list of them. Then it is very easy to write code that check for parameters and get the value if they exist.

I wrote an article about lists for The View, published in November/December 2006. You can find more details and examples there.

No RatingsRatings 0

  • Previous
  • Next
Jump to page of 1
Skip to main content link. Accesskey S
IBM Lotus Connections Help Tools About