关于生成文档序列号的问题,急!急!急!
客户单位要求我们实现如下的功能:
每当新建一个文档并保存后,文档的某个域的值就要加一,即实现文档序列号的功能
编程思路是:创建一个专门存储序列号的文档,每当新建一个文档的时候都从这个文档中取回下一个号码作为文档序列号。因为用户可能在保存之前退出这个新建文档,所以必须等到存储新建文档的时候对序列号文档加一。
以下为我从人民邮电出版社的《Notes编程疑难详解》中第75页找到的一段程序,有几个地方没有读懂,希望高手指点:
Option Public
Option Explicit
Const COUNTER_FOLDER_FROM_NAME$="(记数文档)"
Function SequentialNumber&(Byval CounterName$,Byval CounterToSave%)
On Error Goto SequentialNumberError
Dim CounterFieldName$
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim docNext As NotesDocument
Dim CounterValue&
Dim FieldValue As Variant
Dim Ret%
Dim item As NotesItem
Dim FolderToBeCreated%
CounterFieldName$="MB"+CounterName$
Set db=session.CurrentDatabase
Set view=db.GetView(COUNTER_FOLDER_FROM_NAME$)
If view Is Nothing Then
FolderToBeCreated%=True
End If
Do
If Not FolderToBeCreated% Then
view.Refresh
Set doc=Nothing
Set doc=view.GetFirstDocument()
End If
If doc Is Nothing Or FolderToBeCreated% Then
Set doc=New NotesDocument(db)
doc.Form=COUNTER_FOLDER_FROM_NAME$
Call doc.Save(True,False)
doc.PutInFolder COUNTER_FOLDER_FROM_NAME$
If FolderToBeCreated% Then
Set view=db.GetView(COUNTER_FOLDER_FROM_NAME$)
FolderToBeCreated%=False
End If
Else
Set item=doc.GetFirstItem(CounterFieldName$)
If item Is Nothing Then
Call doc.ReplaceItemValue(CounterFieldName$,0)
Call doc.Save(False,False)
Else
FieldValue=doc.GetItemValue(CounterFieldName$)
If Not CounterToSave% Then
CounterValue&=FieldValue(0)+1
Exit Do
Else
Call doc.ReplaceItemValue(CounterFieldName$,FieldValue(0)+1)
Ret%=doc.Save(False,False)
If Ret% Then
CounterValue&=FieldValue(0)+1
Exit Do
End If
End If
End If
End If
Loop
Set doc=view.GetNextDocument(doc)
Do While Not doc Is Nothing
Set docNext=view.GetNextDocument(doc)
Call doc.Remove(True)
Set doc=docNext
Loop
SequentialNumber&=CounterValue&
SequentialNumberExit:
Exit Function
SequentialNumberError:
Msgbox "SequentialNumber",Err,Error$
SequentialNumber&=-1
Goto SequentialNumberExit
End Function
书中写到:
函数的调用方式为:
SequentialNumber&(CounterName$,CounterToSave%)
此函数支持多个序列的序列号,CounterName$参数为要使用的序列号名称。CounterToSave%参数为True时,函数取回下一个序列号,并将该号码加一;当CounterToSave%参数为False时,函数只取回下一个序列号。
我的问题是:
1.函数调用时CounterName$参数应该以什么作为输入参数?
2.上面程序中的语句中的"MB"是何用意?
CounterFieldName$="MB"+CounterName$