Sub Initialize
Dim ses As New NotesSession
Dim formula As String, server As String, dbpath As String
try:
On Error Goto catch
' задай значения параметров server, dbpath, formula
If SetReplicationFormula(server, dbpath, ses.UserName, formula) Then
Print "set formula",formula
End If
Exit Sub
catch:
'Call errh(Err, Error, Erl, Getthreadinfo(1), False)
Exit Sub
End Sub
Function SetReplicationFormula(TargetServer As String, TargetDatabase As String, userName As String, Byval replformula As String) As Boolean
Dim NoteID As Long, DBhandle As Long, NoteHandle As Long
Dim FormulaHandle As Long, LockObjectAddress As Long
Dim OriginatorID(6) As Long
Dim status As Integer, exists As Integer
Dim retFormulaLength As Integer, retCompileError As Integer, retCompileErrorLine As Integer
Dim retCompileErrorColumn As Integer, retCompileErrorOffset As Integer, retCompileErrorLength As Integer
Dim puserName As String, lmbcsFormula As String
try:
On Error Goto catch
If TargetServer = "" Or TargetDatabase = "" Or userName = "" Then Exit Function
puserName = Space(1024)
Call OSPathNetConstruct( 0, TargetServer, TargetDatabase, puserName )
Call NSFDbOpen( puserName, DBhandle)
If DBhandle = 0 Then Exit Function
'This function returns the note ID of a form, view, shared folder, macro, or field note
Call NIFFindDesignNote (DBhandle, userName, &H0800, NoteID)
If NoteID = 0 Then
exists = False
'This function creates a new note in memory
Call NSFNoteCreate (DBhandle, NoteHandle)
'This function generates a new Originator ID (OriginatorID) used to uniquely identify a note
Call NSFDbGenerateOID( DBhandle, OriginatorID(0))
'This function sets the specified portion of a note header in memory to a particular value
Call NSFNoteSetInfo (NoteHandle, 2, OriginatorID(0))
Call NSFNoteSetInfo (NoteHandle, 3, &H0800)
Else
exists = True
Call NSFNoteOpenExtended (DBhandle, NoteID, &H0800, 0, 0, NoteHandle)
End If
If Not NoteHandle = 0 Then
'This function accepts a LMBCS string containing a formula and translates the formula into binary form
%rem
здесь то, что ты считаешь не нужным
lmbcsFormula = lmbcsToNative(replformula)
%endrem
status = NSFFormulaCompile( 0, 0, lmbcsFormula, Len(lmbcsFormula), FormulaHandle, retFormulaLength, retCompileError,_
retCompileErrorLine, retCompileErrorColumn, retCompileErrorOffset, retCompileErrorLength)
If Not status = 0 Then
Print "NSFFormulaCompile error", status
Print replformula
Print lmbcsFormula
End If
If Not FormulaHandle = 0 Then
'Deletes a named item from the in-memory copy of a note.
If exists Then Call NSFItemDelete (NoteHandle, "$ReplClassMasks", 15)
Call NSFItemAppendTextList (NoteHandle, "$ReplClassMasks", "2047", 4, 0)
If exists Then Call NSFItemDelete (NoteHandle, "$ReplFields", 11)
Call NSFItemAppendTextList (NoteHandle, "$ReplFields", "", 0, 0)
If exists Then Call NSFItemDelete (NoteHandle, "$ReplForm", 9)
Call NSFItemAppendTextList (NoteHandle, "$ReplForm", "0", 1, 0)
If exists Then Call NSFItemDelete( NoteHandle, "$ReplFormula", 12)
'OSLockObject locks a memory object (preventing its physical relocation) and returns a pointer to its locked address in memory.
LockObjectAddress = OSLockObject(FormulaHandle)
'This function adds an item (field) to an open note
Call NSFItemAppend (NoteHandle, 4, "$ReplFormula", 12, &H0600, LockObjectAddress, Clng(retFormulaLength))
'OSUnlockObject is called to indicate that an application no longer needs physical access to the specified object.
Call OSUnlockObject (FormulaHandle)
'OSMemFree is used to deallocate a block of Domino memory that was created via OSMemAlloc.
Call OSMemFree (FormulaHandle)
If exists Then Call NSFItemDelete (NoteHandle, "$ReplPrivateFolder", 18)
Call NSFItemAppendTextList (NoteHandle, "$ReplPrivateFolder", "", 0, 0)
If exists Then Call NSFItemDelete (NoteHandle, "$ReplSrcServers", 15)
Call NSFItemAppendTextList( NoteHandle, "$ReplSrcServers", "-", 1, 0)
Call NSFItemSetText( NoteHandle, "$ReplVersion", "2", 1)
If exists Then Call NSFItemDelete( NoteHandle, "$ReplView", 9)
Call NSFItemAppendTextList( NoteHandle, "$ReplView", "", 0, 0)
Call NSFItemSetText( NoteHandle, "$TITLE", userName, Len(userName))
status = NSFNoteUpdate( NoteHandle, 0)
If status <> 0 Then
Print "NSFNoteUpdate error", status
Else
SetReplicationFormula = True
End If
End If
'This function deallocates the memory associated with an open note
Call NSFNoteClose( NoteHandle)
End If
'This subroutine closes a previously opened database
Call NSFDbClose( DBhandle)
Exit Function
catch:
' Call errh(Err, Error, Erl, getthreadifon(1), False)
Exit Function
End Function