Attribute VB_Name = "EVSB"
Option Explicit

'Declare EVCHK3.DLL & EVMOV3.DLL functions
Declare Function EVCHK3 Lib "EVCHK3.DLL" (lpUserSB As SecureBlock) As Integer
Declare Function EVMOV3 Lib "EVMOV3.DLL" (lpUserSB As SecureBlock) As Integer

Sub ClearSB(lpSB As SecureBlock)
    ' clear the given SecureBlock structure to a known state
    lpSB.ID = "AZSB"
    lpSB.DRV = Chr$(0)
    lpSB.AUTH = Chr$(0)
    lpSB.PTYPE = Chr$(0)
    lpSB.PROD = String$(9, 0)
    lpSB.SNP = 0
    lpSB.HNUC = 0
    lpSB.AVERS = 0
    lpSB.ECL = 0
    lpSB.DFT = 0
    lpSB.EDL = 0
    lpSB.ETL = 0
    lpSB.ED = String$(9, 0)
    lpSB.CHKSUM = Chr$(0)
    lpSB.NUC = 0
    lpSB.NUL = 0
    lpSB.ICR = 0
    lpSB.ACCFLG = String$(8, 0)
    lpSB.USRDAT = String$(8, 0)
    lpSB.RTYPE = Chr$(0)
    lpSB.RNAME = String$(51, 0)
    lpSB.RCOMP = String$(51, 0)
    lpSB.RLOC = String$(51, 0)
    lpSB.RDATE = String$(9, 0)
    lpSB.CDATE = String$(9, 0)
    lpSB.RSRVD1 = String$(20, 0)
    lpSB.SECSTR = String$(256, 0)
    lpSB.FUNC = 0
    lpSB.STAT1 = 0
    lpSB.STAT2 = 0
    lpSB.STAT3 = 0
    lpSB.SOURCE = String$(63, 0)
    lpSB.TARGET = String$(63, 0)
    lpSB.RSRVD2 = String$(2, 0)
    lpSB.PIN = 0
    lpSB.RUC = 0
    lpSB.PCNT = 0
    lpSB.RSRVD3 = String$(2, 0)
    lpSB.UNINST = 0
    lpSB.REG = 0
    lpSB.RSRVD4 = String$(4, 0)
    lpSB.CODE = String$(30, 0)
    lpSB.RSRVD5 = String$(74, 0)
End Sub

Function FormatError$(userSB As SecureBlock)
    Dim t As String

    ' format the SB error code into the Az-Tech display format
    ' i.e. 7XXX-XXXX-XXXX
    t$ = Left$("0000", 4 - Len(Hex$(userSB.STAT1))) + Hex$(userSB.STAT1)
    t$ = t$ + "-" + Left$("0000", 4 - Len(Hex$(userSB.STAT2))) + Hex$(userSB.STAT2)
    t$ = t$ + "-" + Left$("0000", 4 - Len(Hex$(userSB.STAT3))) + Hex$(userSB.STAT3)

    FormatError$ = t$
End Function

