Attribute VB_Name = "msmapi"
Public lastmsm, sema

Const timeout = 60

Sub msminit(ByVal SERVER As String)
    WIMsmapi.msm.LoadFromMCO (Environ("windir") + "\" + SERVER + ".mco")
    lastmsm = Timer
    WIMsmapi.msm.Login
    sema = WIMsmapi.msm.Xecute("W $$NEW^%SEMA() D INIT^BMUEGVA(" + FIRMA + "," + FIL + ")")
End Sub

Function msmcall(ByVal command As String) As String

    If WIMsmapi.msm.Connected = 0 Then
        WIMsmapi.msm.Login
        WIMsmapi.msm.Xecute ("D MEMPOP^%SEMA(" + sema + ")")
    End If
    msmcall = WIMsmapi.msm.Xecute(command)
    lastmsm = Timer
  
End Function

Sub msmtimeout()

    If Timer - lastmsm > timeout And WIMsmapi.msm.Connected > 0 Then
        WIMsmapi.msm.Xecute ("D MEMPUSH^%SEMA(" + sema + ")")
        WIMsmapi.msm.Logout
    End If

End Sub

Sub msmexit()
    If WIMsmapi.msm.Connected = 0 Then
       WIMsmapi.msm.Login
    End If
    WIMsmapi.msm.Xecute ("K ^XWSEM(" + sema + ")")
    If WIMsmapi.msm.Connected > 0 Then
       WIMsmapi.msm.Logout
    End If
End Sub

 
Function Piece(ByVal s As String, ByVal tr As String, ByVal n As Integer) As String
    n1 = 1
    r = ""
    For i = 1 To Len(s)
        c = Mid$(s, i, 1)
        If c = tr Then
           n1 = n1 + 1
          Else
           If n = n1 Then r = r & c
        End If
    Next
    Piece = r
End Function

Function da_msm_vb(ByVal d As String) As Date
  d = Val(d)
  Tag = d Mod 100
  mon = d \ 100 Mod 100
  jahr = (d \ 100 \ 100) + 1900
  da_msm_vb = Format(Tag) + "." + Format(mon) + "." + Format(jahr)
End Function
 
Function da_vb_msm(ByVal d As Variant) As String
  If Format(d) = "" Then da_vb_msm = "": Exit Function
  Tag = Day(d)
  mon = Month(d)
  jahr = Year(d)
  da_vb_msm = Format(jahr - 1900) + Format(mon, "00") + Format(Tag, "00")
End Function

 
 



