Subject: Question for Mika, one more…
Sorry to ask you too much.
I have one more question…
I am using the other script library which create the replica id and store in a field, then using your cnotes library I update the selected user address book replica id ( user are in Citrix environment, so I can map the drive and run the script).
If I am creatig two separte agent it working fine, but when I tried to combine both the agent and create one script to
-
create replica id and put it in field
-
using cnotes get the value from that field and update the user names.nsf replica id.
but now I am getting the following error…
DUPLICATE PUBLIC name TIMEDATE in use
Following is other script library and code
[Agent: Generate Unique Rep ID] – stamps a field called NewRepID with a “unique” rep id.
Option Declare
Use “C-API Declarations”
Sub Click(Source As Button)
On Error Goto ErrHandler
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Dim dtNow As New NotesDateTime(Now())
Dim memman As New memoryManagerExt
Dim p As Long
Dim p0 As Long
Dim hdb As Long
Dim replInfo As DBREPLICAINFO
Dim s As New NotesSession
Dim db As NotesDatabase
Dim rc As Integer
Dim buffID As String*256
Dim intDate1 As Integer
p = memman.newBuffer(256)
p0 = p
Set db = s.CurrentDatabase
If p > 0 Then
hdb = openDb(db)
rc = W32_NSFDbReplicaInfoGet(hdb, replInfo)
Call W32_ODSWriteMemoryByVal(p, ODS_BYTE, dtNow.LSLocalTime & Chr(0), 256)
Call W32_ConvertTextToTIMEDATE(0, 0, p0, 256, replInfo.ID)
Call W32_ConvertTIMEDATEToText(0, 0, replInfo.ID, buffID, 256, intDate1)
Print "Setting new timestamp to: " & buffID & Chr$(0)
Dim t1 As Variant, t2 As Variant
Dim L1 As Integer, L2 As Integer
t1 = Hex(replinfo.id.innards(1))
t2 = Hex(replinfo.id.innards(0))
L1 = Len(t1)
L2 = Len(t2)
If ((L1 > 8) Or (L2 > 8)) Then
Msgbox “weirdness, unable to complete operation”
Exit Sub
End If
If (L1<8) Then
t1 = PadRepPart(Cstr(t1))
End If
If (L2<8) Then
t2 = PadRepPart(Cstr(t2))
End If
Print "New RepID: " & t1 & “:” t2
Call uidoc.FieldSetText(“NewRepID”, t1 & t2)
End If
Call uidoc.refresh
Delete memman
continueOK:
If hdb <> 0 Then
rc = W32_NSFDbClose(hdb&)
End If
Exit Sub
ErrHandler:
Msgbox Err() & " : " & Error$()
Resume continueOK
End Sub
Function PadRepPart(b As String) As String
Dim i As Integer, bLen As Integer
Dim pad As String
Dim retStr As String
bLen = Len(b)
i=0
retStr = b
If (bLen < 8) Then
pad = “”
While (i+bLen) < 8
i = i +1
pad = pad & “0”
Wend
retStr = pad & retStr
End If
PadRepPart = retStr
End Function
…
[C API Declaration - script library]
Option Public
Option Declare
Public Const NO_ERROR% = 0
Public Const OS_TRANSLATE_LMBCS_TO_UNICODE% = 20
Public Const OS_TRANSLATE_UNICODE_TO_LMBCS% = 23
Public Const wAPIModule$ = “NNOTES” ’ Windows/32
’ ++ CORE API CALLS ++
Declare Public Function W32_NSFDbOpen Lib wAPIModule Alias “NSFDbOpen” _
( Byval P As String, hDB As Long) As Integer
Declare Public Function W32_NSFDbClose Lib wAPIModule Alias “NSFDbClose” _
(Byval hDB As Long) As Integer
Declare Public Function W32_NSFDbIsLocallyEncrypted Lib wAPIModule Alias “NSFDbIsLocallyEncrypted” _
( Byval hDB As Long, _
pBool As Integer) As Integer
Declare Public Function W32_OSPathNetConstruct Lib wAPIModule Alias “OSPathNetConstruct” _
( Byval NullPort As Long, _
Byval Server As String, _
Byval FIle As String, _
Byval PathNet As String) As Integer
Declare Public Function W32_NSGetServerList Lib wAPIModule Alias “NSGetServerList” _
(Byval pPortName As Lmbcs String, _
retServerList As Long) As Integer
Declare Public Function W32_NSGetServerListAll Lib wAPIModule Alias “NSGetServerList” _
(Byval pPortNameNULL As Long, _
retServerList As Long) As Integer
Declare Public Function W32_NSPingServer Lib wAPIModule Alias “NSPingServer” _
(Byval ServerName As Lmbcs String, _
loadIndex As Long, _
hList As Long) As Integer
Declare Public Function W32_ListGetText Lib wAPIModule Alias “ListGetText” _
(Byval pList As Long, _
Byval fPrefixDataType As Integer, _
Byval EntryNumber As Integer, _
retTextPtr As Long, _
retTextLength As Integer) As Integer
Declare Public Function W32_ListGetNumEntries Lib wAPIModule Alias “ListGetNumEntries” _
(Byval pList As Long, _
Byval typeRepresent As Integer) As Integer
Declare Public Function W32_OSLockObject Lib wAPIModule Alias “OSLockObject” _
(Byval handle As Long) As Long
Declare Public Sub W32_OSUnlockObject Lib wAPIModule Alias “OSUnlockObject” _
(Byval handle As Long)
Declare Public Sub W32_OSMemFree Lib wAPIModule Alias “OSMemFree” _
(Byval handle As Long)
Declare Public Function W32_OSTranslateToStr Lib wAPIModule Alias “OSTranslate” _
(Byval TranslateMode As Integer, _
Byval pInString As Long, _
Byval InLength As Integer, _
Byval OutString As Unicode String, _
Byval OutLength As Integer) As Integer
Declare Public Sub W32_OSLoadString Lib wAPIModule Alias “OSLoadString” _
(Byval null1 As Long, _
Byval ErrorCode As Integer, _
Byval ErrorString As String, _
Byval ErrorStringLength As Integer)
Const ODS_BYTE = 3
Public Type TIMEDATE
innards(1) As Long
End Type
Public Type DBREPLICAINFO
ID As TIMEDATE
Flags As Integer
CutoffInterval As Integer
Cutoff As TIMEDATE
End Type
Declare Function W32_NSFDbReplicaInfoGet Lib wAPIModule Alias “NSFDbReplicaInfoGet” _
(Byval hdb As Long, _
replInfoStruct As DBREPLICAINFO) As Integer
Declare Function W32_NSFDbReplicaInfoSet Lib wAPIModule Alias “NSFDbReplicaInfoSet” _
(Byval hdb As Long, _
replInfoStruct As DBREPLICAINFO) As Integer
Declare Function W32_ConvertTIMEDATEToText Lib wAPIModule Alias “ConvertTIMEDATEToText” _
(Byval nullFormat As Long, _
Byval textFormat As Long, _
td As Any, _
Byval Buff As String, _
Byval maxlen As Integer, _
textLength As Integer) As Integer
Declare Function W32_ConvertTextToTIMEDATE Lib wAPIModule Alias “ConvertTextToTIMEDATE” _
(Byval nullFormat As Long, _
Byval textFormat As Long, _
ptrTextBuff As Long, _
Byval maxlen As Integer, _
td As TIMEDATE) As Integer
Declare Function W32_OSMemAlloc Lib wAPIModule Alias “OSMemAlloc”(Byval flags As Integer, Byval length As Integer, handle As Long) As Integer
Declare Sub W32_OSMemoryFree Lib wAPIModule Alias “OSMemoryFree”(Byval h As Long)
Declare Function W32_OSMemoryUnlock Lib wAPIModule Alias “OSMemoryUnlock”(Byval h As Long) As Integer
Declare Function W32_OSMemoryLock Lib wAPIModule Alias “OSMemoryLock”(Byval h As Long) As Long
Declare Function W32_OSMemoryAllocate Lib wAPIModule Alias “OSMemoryAllocate”(Byval t As Long, Byval size As Long, handle As Long) As Integer
Declare Sub W32_ODSWriteMemoryStr Lib wAPIModule Alias “ODSWriteMemory” (pDest As Long, Byval typeODS As Integer, Byval pSource As String, Byval Iterations As Integer)
Declare Sub W32_ODSWriteMemoryByVal Lib wAPIModule Alias “ODSWriteMemory” (pDest As Long, Byval typeODS As Integer, Byval ppSource As Any, Byval Iterations As Integer)
’ ++ FANCY THICK CLIENT / UI CALLS
Public Const wAPIModuleWS$ = “NNOTESWS.DLL”
Public Const NPB_TWOLINE% = 1
Public Const START_PB% = 1
Public Const UPDATE_PB% = 2
Public Const STOP_PB% = 3
'-- Procedures in nnotesws.dll
Declare Public Function W32_NEMProgressBegin Lib wAPIModuleWS Alias “NEMProgressBegin” _
(Byval wFlags As Integer) As Long
Declare Public Sub W32_NEMProgressEnd Lib wAPIModuleWS Alias “NEMProgressEnd” _
(Byval hwnd As Long)
Declare Public Sub W32_NEMProgressSetBarPos Lib wAPIModuleWS Alias “NEMProgressSetBarPos” _
(Byval hwnd As Long, _
Byval dwPos As Long)
Declare Public Sub W32_NEMProgressSetBarRange Lib wAPIModuleWS Alias “NEMProgressSetBarRange” _
(Byval hwnd As Long, _
Byval dwMax As Long)
Declare Public Sub W32_NEMProgressSetText Lib wAPIModuleWS Alias “NEMProgressSetText” _
(Byval hwnd As Long, _
Byval pcszLine1 As String,_
Byval pcszLine2 As String)
Public Class memoryManager
Public OpenHandles List As Variant
Public Function LockObject(h) As Long
If h=0 Then Exit Function
LockObject = W32_OSLockObject(h)
OpenHandles(h) = LockObject
End Function
Public Sub UnlockObject(h)
If h =0 Then Exit Sub
If Iselement(OpenHandles(h)) Then
W32_OSUnlockObject h
Erase OpenHandles(h)
End If
End Sub
Public Function UnlockAll
Forall hh In Me.openHandles
Call Me.unlockObject(hh)
End Forall
End Function
Sub Delete
Me.unlockAll
End Sub
End Class
Public Class memoryManagerExt As memoryManager
Public buffers List As Long
Public Function newBuffer(lenBuffer As Long) As Long
Dim irc As Integer
Dim hBuff As Long
irc = W32_OSMemoryAllocate(0, lenBuffer, hBuff)
If irc=0 Then
If hBuff=0 Then Exit Function
buffers(hBuff) = W32_OSMemoryLock(hBuff)
newBuffer = buffers(hBuff)
Else
printCAPIError(irc)
End If
End Function
Sub Delete
Forall p In Me.buffers
W32_OSMemoryUnlock Listtag(p)
W32_OSMemoryFree Listtag(p)
End Forall
End Sub
End Class
Public Function getCAPIError(ErrorNum As Integer) As String
Dim retError As String * 256
Call W32_OSLoadString(0, ErrorNum And &h03ffffff, retError, 256)
getCAPIError = Strleft(retError, Chr(0))
End Function
Public Sub printCAPIError(ErrorNum As Integer)
Dim errorString As String
errorString = getCAPIError(ErrorNum)
Print "C API Error: " & errorString
End Sub
Function openDb(ndb As NotesDatabase) As Long
Dim retPath As String*1024
Dim irc As Integer
Dim h As Long
W32_OSPathNetConstruct 0&, ndb.Server, ndb.FilePath, retPath
irc = W32_NSFDbOpen(retPath, h)
If (irc <> 0) Then
Call printCAPIError(irc)
End If
openDB = h
End Function
…
Why I am getting the error??
Thanks again
Lisa