Sub DispLceError(iSessionId As Integer, sSource As String)
    ' this function displays LANSA Open errors.
    ' Note that it is only applicable if LceDisplayErrors is off
    ' otherwise it will never get called, as LANSA takes care of its
    ' own error messages
    
    Dim i As Integer
    Dim sErrDesc As String, iErrNo As Long
    Dim sMsg As String, nMsgs As Integer
    
    Dim msgBuff As String ' message buffer to contain final message
   
    msgBuff = ""
    ' Get error status
    sErrDesc = String((MESSAGE_LENGTH + 1), Chr$(0))
    Call LceGetStatus(iErrNo, sErrDesc, MESSAGE_LENGTH)
    ' if there was an error
    If iErrNo > 0 Then
        ' prepare header message with error description
        msgBuff = sGetText("Error : ") & str(iErrNo) & " " & sSource
        msgBuff = msgBuff & Chr(13) & sErrDesc & Chr(13) & Chr(13)
        ' read remaining messages
        iRet = LceGetMessageCount(iSessionId, nMsgs)
        For i = 1 To nMsgs '
            sMsg = String(MESSAGE_LENGTH * 3, Chr(0))
            iRet = LceGetMessage(iSessionId, i, sMsg, MESSAGE_LENGTH)
            sMsg = sTrim(sMsg) ' sTrim detects null terminated strings
            msgBuff = msgBuff + sMsg ' add message to buffer
        Next              
    Else
        ' no error just display message
        msgBuff = sGetText("Error") & " : " & sSource
    End If
    msgBox msgBuff ' display errors
End Sub