Sub Initialize
Dim session As New NotesSession '定義當前的存儲
Dim db As NotesDatabase '設置當前的數據庫
Dim dc As NotesDocumentCollection '定義當前文檔集合
Dim doc As NotesDocument '定義單個文檔
Dim item As NotesItem '定義單個項目
Set db = session.CurrentDatabase '取得當前數據庫
Set dc = db.UnprocessedDocuments '取得待處理的文檔集合
Set doc = dc.GetFirstDocument '取得首個操作文檔
REM Get first FooBar item
Set item = doc.GetFirstItem("FooBar") '取得首個名為"FooBar"的項目
While Not(item Is Nothing)
Messagebox item.Text,, item.Name '顯示項目的值和名稱
REM Remove item from memory
Call item.Remove '從內存移除此項目
REM Get next FooBar item
Set item = doc.GetFirstItem("FooBar") '取得下一個名為"FooBar"的項目
Wend
End Sub
二、取已選值
Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.CurrentDatabase
Dim dsSel As NotesDocumentCollection
Set dsSel = db.UnProcessedDocuments
dsSel 就是你所選的所有文件(集合)
(若無打勾則是有黑框的單一文件,
但仍要下列步驟才能取出文件資料)
Dim d As NotesDocument
Set d = dsSel.GetFirstDocument
do until d is nothing
d.欄位名稱(0)... 用於欄位是單一值
Forall V in d.欄位名稱 ... 用於欄位是多重值
Vtmp = V
End Forall
set d = dsSel.GetNextDocument(d)
loop
三、常用代碼
1.检测当前用户是不是文档的创建者,如果不是,不允许编辑文档。
Sub Querymodechange(Source As Notesuidocument. Continue As Variant)
Dim session As New NotesSession
Dim doc As notesdocument. Dim userName As New NotesName(session.UserName)
Set doc=source.document. If Not ( source.EditMode ) Then
If ( doc.authors(0) = username.CANONICAL ) Then continue=True
Else Msgbox "您不是此文档的创建人,不可以修改!",0,"文档数据库"
continue=False
End If End If End Sub
2.退出时检测关键的域不能为空
Sub Click(Source As Button)
Dim w As New notesuiworkspace
Dim uidoc As notesuidocument. Dim doc As notesdocument. Set uidoc=w.currentdocument. name1=uidoc.fieldgettext("name")
If name1="" Then
Messagebox "姓名不能为空!",0,"通讯录"
Exit Sub
End If
Call uidoc.save
Call uidoc.close
End Sub
3.用私有视图来显示需要当前用户处理的文档,用以下视图公式:
注意建立视图时不要选中"保存到本地"选项,否则调试不便.
SELECT Form = "收文1" & NextApprover=@Name([CN];@V3UserName)
4.Notes中Active控件
当文档中添加OLE或其他通用的ActiveX控件后,在文档的script编辑框右侧中,会自动添
加各种属性和方法在notes的类列表中.在script中声明该对象的 方法如下:
Sub Postopen(Source As Notesuidocument.
Dim w as notesuiworkspace
Dim uidoc as notesuidocument. Dim aa As Variant
Set w =New notesuiworkspace
Set uidoc =w.currentdocument. Set aa=uidoc. getObject("Chart")'该句为ole对象声明,注意Chart是你给对象起的名
字 '接下来你就可以通过aa.**来调用其方法和属性了.
End Sub
5.是否保存
在表单中设定一个域,名称为saveoption
下列公式添加到返回按钮中,决定文件退出是否保存
FIELD saveoptions:="1"; 保存 FIELD saveoptions:="0"; 不保存
6.用公式弹出对话框,按确定继续,取消返回.
@If(@DialogBox("表单名";[AutoHorzFit]:[AutoVertFit];"表单标题");"";@Return("
"))
7.用script弹出对话框,按确定继续,取消返回
Dim w as notesuiworkspace
If Not w.dialogbox("表单名",True,True,False,True,False,False,"填写")
Then doc.close'用户按取消退出
Exit Sub
End If
8.视图中删除文档语句
@Command([EditClear]);
@Command([ViewRefreshFields])
9.检测是否是周末
Dim dt as notesdatetime
call dt.setnow
If Weekday(dt.lslocaltime)=7
Then'是周六耶,
dt.adjustday(2) '加两天到星期一
Elseif Weekday(dt.lslocaltime)=1
Then'周日加一天
dt.adjustday(1)
End If
10.得到当前的服务器和路径
公式: ResideServer := @Subset(@DbName; 1)
CurrentPath := @Subset(@DbName; -1)
DirOnly := @If(@Contains(CurrentPath; "\\");
@LeftBack(CurrentPath; "\\") + "\\"; "");
DbFile := DirOnly + "***.NSF";
11.得到当前用户名
公式:@Name([CN];@V3UserName)
script:Dim s as notessession
Dim myname as newnotesname(s.username)
messagebox myname.common
12.得到当前日期公式:
@today @date(@created)
script:Dim dt as notesdatetime
Set dt=New notesdatetime("")
Call dt.setnow
13.常用全局对象声明 '-----对象变量-----
Dim w As NotesUIWorkspace
Dim s As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim uidoc As NotesUIdocument. Dim doc As Notesdocument. Dim item As NotesItem
Dim dt As NotesDateTime
Dim username as notesname
14.一些计算域,开始时没有值,如果不给它一个值会报错,以下公式给计算域赋值
@if(Bfield="";0;Bfield)
15.特殊字符
@char(13)可以在@prompt提示框中显示回车 script中用函数chr(13)
16.【Lotus编程※域操作】对话列表框--使用公式从SQL Server数据库中读取数据
(1)读数据:@DbCommand("odbc":"nocache";"数据库服务器名";"用户名";"密码";"sql语句")
(2)分级读:a:=order_form.commoid1;
@If(order_form.commoid1="";@DbCommand("odbc":"nocache";"domino";"cadiec";"cadiec1234";"select name from ptype where leveal=1")+"|"+@DbCommand("odbc":"nocache";"domino";"cadiec";"cadiec1234";"select typeid from ptype where leveal=1");@If(@Elements(@DbCommand("odbc":"nocache";"domino";"cadiec";"cadiec1234";"select name from ptype where parid='"+order_form.commoid1+"'"));@DbCommand("odbc":"nocache";"domino";"cadiec";"cadiec1234";"select name from ptype where parid='"+order_form.commoid1+"'")+"|"+@DbCommand("odbc":"nocache";"domino";"cadiec";"cadiec1234";"select typeid from ptype where parid='"+order_form.commoid1+"'");@DbCommand("odbc":"nocache";"domino";"cadiec";"cadiec1234";"select name from ptype where typeid='"+a+"'")+"|"+@DbCommand("odbc":"nocache";"domino";"cadiec";"cadiec1234";"select typeid from ptype where typeid='"+a+"'")))
如何抓群組內的成員名單
books = session.AddressBooks
done = False |