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" & [email protected]([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 |