With reference to Olav Lahmann's tip :
http://searchdomino.techtarget.com/tip/1,289483,sid4_gci534097,00.html
I modified the code slightly to include a form for a Dialogbox, in order to get a more presentable function, and to avoid several agents.
The function
- displays the current dictionary.
- searches the clients data dir in order to allow selection of available .dic files except user.dic
- Sets Notes.ini to use selected dictionary
The use of @Dialogbox requires a form to be triggered from, and therefore this method isn't as dynamical as one might wish... But I guess that it still needs a lot of coding to be perfect.
I have only included some dictionaries that we use, if you use others, they will of course have to be specified in both the "Sub Calculate" and the OK button.
*** Shared action to open the dialogbox:
Dlgform:="DlgSelectDictionary";
title:="Change spelling dictionary";
@DialogBox( Dlgform ; [AutoHorzFit] : [AutoVertFit]
: [NoCancel] : [NoNewFields] : [NoFieldUpdate]
: [SizeToTable] : [NoOKCancel] ; title )
--------------------------------
*** Form: i.e. "DlgSelectDictionary"
postopen on form:?
Sub Postopen(Source As Notesuidocument)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Call uidoc.refresh
Call calculate()
End Sub
--------------------------------
*** Sub Calculate on form:
Sub Calculate()
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim s As New NotesSession
Dim doc As Notesdocument
Dim sDictionary As String
Dim boxType As Long, ret As Integer
Dim sDir As String, iFile As Integer
Dim FileName As String
Dim item As NotesItem
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.document
Set item = doc.GetFirstItem( "AvailableDics" )
boxType& = MB_YESNO + MB_ICONQUESTION
sDictionary = s.GetEnvironmentString( "SPELL_LANG", True )
Dim sTempString(1 To 9, 1 To 3) As String
sTempString(1,1) = "Norwegian (Bokmal)"
sTempString(1,2) = "1044"
sTempString(1,3) = "norbok.dic"
sTempString(2,1) = "Norwegian (Nynorsk)"
sTempString(2,2) = "2068"
sTempString(2,3) = "nornyn.dic"
sTempString(3,1) = "English (USA)"
sTempString(3,2) = "1036"
sTempString(3,3) = "us.dic"
sTempString(4,1) = "English (UK)"
sTempString(4,2) = "2057"
sTempString(4,3) = "uk.dic"
sTempString(5,1) = "German (Standard)"
sTempString(5,2) = "1033"
sTempString(5,3) = "deutsch.dic"
sTempString(6,1) = "French"
sTempString(6,2) = "1040"
sTempString(6,3) = "francais.dic"
sTempString(7,1) = "Spanish"
sTempString(7,2) = "1034"
sTempString(7,3) = "espana.dic"
sTempString(8,1) = "Danish"
sTempString(8,2) = "1030"
sTempString(8,3) = "dansk.dic"
sTempString(9,1) = "Finnish"
sTempString(9,2) = "1035"
sTempString(9,3) = "suomi.dic"
LB1 = Lbound(sTempString, 1)
UB1 = Ubound(sTempString, 1)
LB2 = Lbound(sTempString, 2)
UB2 = Ubound(sTempString, 2)
For i = LB1 To UB1
If sTempString(i, 2) = sDictionary Then
doc.TmpCurrentDic=sTempString(i, 1)
ret=6
End If
Next
If ret = 6 Then
wildCard = "*.dic"
pathName = s.GetEnvironmentString( "Directory", True )
fileName = Dir$(pathName + wildcard, 0)
Do While fileName <> ""
For j = LB1 To UB1
If Lcase(fileName)=Lcase(sTempString(j, 3)) Then
Call item.AppendToTextList(sTempString(j,1) & "|" & sTempString(j,3))
End If
Next
Call uidoc.refresh
fileName = Dir$()
Loop
Else
Exit Sub
End If
Exit Sub
End Sub
--------------------------------
*** Fields on form:
I made a form with a table in order to use the @Dialogbox function
with the following fields:
** Hidden and computed:
fieldname: "AvailableDics"
Computed value: ["AvailableDics"]
fieldname: "TmpCurrentDic"
Computed value: ["TmpCurrentDic"]
fieldname: "SaveOptions"
Computed value: ["0"]
--------------------------------
** UNhidden and computed
fieldname: "CurrentDic"
Computed value: [@If(TmpCurrentDic="";"[Unknown dictionary!]";
TmpCurrentDic)]
--------------------------------
** UNhidden and editable (radiobutton)
fieldname: "DspAvailableDics"
Set field to "Use formula for choices"
where choices (formula) is:
remove:="user.dic";
ret1:=@Implode(AvailableDics;"~");
ret2:=@ReplaceSubstring(ret1;remove;"");
@Explode(ret2;"~")
--------------------------------
*** OK button
Then you need an "OK" button on the form:
with folowing code
Sub Click(Source As Button)
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As Notesdocument
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.document
Dim sTempString(1 To 9, 1 To 3) As String
sTempString(1,1) = "Norwegian (Bokmal)"
sTempString(1,2) = "1044"
sTempString(1,3) = "norbok.dic"
sTempString(2,1) = "Norwegian (Nynorsk)"
sTempString(2,2) = "2068"
sTempString(2,3) = "nornyn.dic"
sTempString(3,1) = "English (USA)"
sTempString(3,2) = "1036"
sTempString(3,3) = "us.dic"
sTempString(4,1) = "English (UK)"
sTempString(4,2) = "2057"
sTempString(4,3) = "uk.dic"
sTempString(5,1) = "German (Standard)"
sTempString(5,2) = "1033"
sTempString(5,3) = "deutsch.dic"
sTempString(6,1) = "French"
sTempString(6,2) = "1040"
sTempString(6,3) = "francais.dic"
sTempString(7,1) = "Spanish"
sTempString(7,2) = "1034"
sTempString(7,3) = "espana.dic"
sTempString(8,1) = "Danish"
sTempString(8,2) = "1030"
sTempString(8,3) = "dansk.dic"
sTempString(9,1) = "Finnish"
sTempString(9,2) = "1035"
sTempString(9,3) = "suomi.dic"
LB1 = Lbound(sTempString, 1)
LB2 = Lbound(sTempString, 2)
UB1 = Ubound(sTempString, 1)
UB2 = Ubound(sTempString, 2)
If Not doc.DspAvailableDics(0)="" Then
For i = LB1 To UB1
If sTempString(i, 3) = doc.DspAvailableDics(0) Then
SelDic=sTempString(i, 2)
SelDicDsp=sTempString(i, 1)
End If
Next
Call session.SetEnvironmentVar( "SPELL_LANG", SelDic, True )
SL = session.GetEnvironmentString( "SPELL_LANG", True )
Print "You have now changed the spelling dictionary to " & SelDicDsp
Call uidoc.Close
Else
Msgbox "You must select a dictionary.",, "Error!"
End If
End Sub
--------------------------------
*** Cancel button
And a "Cancel" button
code - formula: @Command([FileCloseWindow])
--------------------------------
This was first published in November 2001