Public Sub writeFormula (formula As String, doc As Notesdocument, iname As String)
Dim irc As Integer, formula_buffer As blockid
Dim rethFormula As Long, retFormulaLength As Integer, retCompileError As Integer, wdc As Integer
Dim pFormula As Long, lenFormula As Integer, pFormulaCompiled As Long
' pointer for the new item
Dim pBuff As Long
Dim memMan As New memoryManagerExt
pFormula = memMan.newBuffer (3*Lenb(formula))
Problem1 ->> lenFormula = W32_OSTranslateFromStr (OS_TRANSLATE_UNICODE_TO_LMBCS, formula, Lenb(formula), pFormula, 3*Lenb(formula))
Problem2->> irc = W32_NSFFormulaCompilePtr (0, 0, pFormula, lenFormula, rethFormula, retFormulaLength, retCompileError, wdc, wdc, wdc, wdc)
If irc<>0 Then
Print "*", formula, getError(irc)
Else
'We use formula_buffer block below as an input for decompileFormula routine.
formula_buffer.pool = rethFormula
formula_buffer.block = 0
'Then we obtain the pointer to the buffer containing the compiled formula
pFormulaCompiled = W32_OSLockObject (rethFormula)
'and write it to the item of TYPE_FORMULA.
irc = W32_NSFItemAppend(doc.handle, 0, iname, Len(iname), TYPE_FORMULA, pFormulaCompiled, Clng(retFormulaLength))
'You may uncomment the next line to provide a “sanity check”: verify the formula just written.
Print irc, "*decompile", decompileformula(formula_buffer)
' Finally we unlock the buffer and release the memory.
Call W32_OSUnlockObject (rethFormula)
Call W32_OSMemFree (rethFormula)
End If
End Sub