Lotus Notes常用代码

来源:互联网 发布:linux memmap 编辑:程序博客网 时间:2024/04/30 13:35
Lotus Notes常用代码
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.以下是script错误陷阱代码 
Sub subname On Error Goto Errcode '下面添加你的程序代码 
Exit Sub Errcode: Msgbox "错误 (" & Cstr(Err) & " ) -> " & Error$(Err),16,"错 
误提示" 
Exit Sub 
End Sub 


6.是否保存 
在表单中设定一个域,名称为saveoptions
下列公式添加到返回按钮中,决定文件退出是否保存 
FIELD saveoptions:="1"; 保存 FIELD saveoptions:="0"; 不保存 


7.用公式弹出对话框,按确定继续,取消返回. 
@If(@DialogBox("表单名";[AutoHorzFit]:[AutoVertFit];"表单标题");"";@Return(" 
")) 


8.用script弹出对话框,按确定继续,取消返回 
Dim w as notesuiworkspace 
If Not w.dialogbox("表单名",True,True,False,True,False,False,"填写") 
Then doc.close'用户按取消退出 
Exit Sub 
End If 


9.视图中删除文档语句 
@Command([EditClear]); 
@Command([ViewRefreshFields]) 


10.检测是否是周末 
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 


11.得到当前的服务器和路径 
公式: ResideServer := @Subset(@DbName; 1) ; 
CurrentPath := @Subset(@DbName; -1) ; 
DirOnly := @If(@Contains(CurrentPath; "//"); 
@LeftBack(CurrentPath; "//") + "//"; ""); 
DbFile := DirOnly + "***.NSF"; 


12.得到当前用户名 
公式:@Name([CN];@V3UserName) 
script:Dim s as notessession 
Dim myname as newnotesname(s.username) 
messagebox myname.common 


13.得到当前日期公式: 
@today @date(@created) 
script:Dim dt as notesdatetime 
Set dt=New notesdatetime("") 
Call dt.setnow 


14.常用全局对象声明 '-----对象变量----- 
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 


15.一些计算域,开始时没有值,如果不给它一个值会报错,以下公式给计算域赋值 
@if(Bfield="";0;Bfield) 


16.特殊字符 
@char(13)可以在@prompt提示框中显示回车 script中用函数chr(13) 


17.再notes状态兰中显示进度条
(Declarations) Const NPB_STATUSBAR% = 32 
Declare Sub NEMProgressEnd Lib "nnotesws.dll" ( Byval hwnd As Long ) Declare 
 Function NEMProgressBegin Lib "nnotesws.dll" ( Byval wFlags As Integer ) As 
 Long 
Declare Sub NEMProgressSetBarPos Lib "nnotesws.dll" ( Byval hwnd As Long, By 
val dwPos As Long) 
Declare Sub NEMProgressSetBarRange Lib "nnotesws.dll" ( Byval hwnd As Long,  
Byval dwMax As Long ) 
Declare Sub NEMProgressSetText Lib "nnotesws.dll" ( Byval hwnd As Long, Byva 
l pcszLine1 As String, Byval pcszLine2 As String ) 
Sub Click(Source As Button) 
Dim hwnd As Long Dim i As Long 
Dim j As Long 'Create the progress bar hwnd = NEMProgressBegin( NPB_STATUSBA 
R ) 'Set the bar range - the default is 100 NEMProgressSetBarRange hwnd, 100 

For i = 0 To 100 'Simple delay for the example!! 
For j = 0 To 5000 Next 'Update the bar position NEMProgressSetBarPos hwnd, i 
Next 'Destroy the dialog when we're done NEMProgressEnd hwnd End Sub
原创粉丝点击