Showing posts with label lotusscript. Show all posts
Showing posts with label lotusscript. Show all posts

Thursday, October 11, 2007

Simplifying Evaluate

I came across this tips from Tommy Valand site. Used it and loved it. I have even roll out on production application. He show a way to simplify getting the return value from evaluate function

Dim commonUsername As String
commonUsername = Implode( Evaluate( |@Name( [CN] ; @UserName )| ) )

Just becareful that you know the Evaluate return single value and not multiple value.

Wednesday, July 04, 2007

Export text file with Chinese character encoding

I use an Lotus Script agent to create a text file which get data from documents. Things are working fine until some user starts to key in Chinese characters.

Initially the partial code is as below

Dim fileNum As Integer
Dim filePath
fileNum% = Freefile()
filePath =
Open filePath For Output As fileNum%


The Chinese characters will be shown as boxes in the file. This definitely have to do with the encoding. After some searching I found an easy way to add in the encoding in the the file. Charset = "UTF-8" need to be added to enable proper exporting.

Sample code as below

Dim fileNum As Integer
Dim filePath
fileNum% = Freefile()
filePath =
Open filePath For Output As fileNum% Charset = "UTF-8"


Add to del.icio.us

Tuesday, January 16, 2007

Using List in Simple Form Validation

In LotusScript, List is a very useful collection data type. I've spoken to quite a few developer and not many of them is taking advantage of List data type. Below is a simple validation example using List.

First example, is a typical simple validation I found in a form
Function ValidateSubmit As Boolean
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument

If uidoc.FieldGetText("FirstName") = "" Then
Msgbox "Please enter your first name"
ValidateSubmit = False
Exit Function
Elseif uidoc.FieldGetText("LastName") = "" Then
Msgbox "Please enter your last name"
ValidateSubmit = False
Exit Function
Elseif uidoc.FieldGetText("Gender") = "" Then
Msgbox "Please select your gender"
ValidateSubmit = False
Exit Function
'........ other validation
End If
ValidateSubmit = True
End Function
Second example, fields and messages stored in a List for validation
Function ValidateSubmit As Boolean
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument

Dim fieldList List As String
fieldList("FirstName") = "Please enter your first name"
fieldList("LastName") = "Please enter your last name"
fieldList("Gender") = "Please select your gender"
'...fieldList("OtherFields") = "return message"

Forall f In fieldList
If uidoc.FieldGetText(Listtag(f)) = "" Then
Msgbox f
ValidateSubmit = False
Exit Function
End If
End Forall
ValidateSubmit = True
End Function
As the number of fields to be validated grows, maintaining the List in the second example is much simple than the first example. This is just a very simple example to showcase the use of List. You can even store objects in the List. Try using List if you haven't done so.