VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   4590
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7875
   LinkTopic       =   "Form1"
   ScaleHeight     =   4590
   ScaleWidth      =   7875
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton TestBtn 
      Caption         =   "Test"
      Height          =   375
      Left            =   3000
      TabIndex        =   1
      Top             =   4080
      Width           =   1575
   End
   Begin VB.ListBox List1 
      Height          =   3765
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   7575
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' ==========================================================================
' counter
' (1) set counter
' (2) start counter
' description
'  (1) if set the counter to 0, it means no limitation
'  (2) if the counter decreases to 0, the it stops and becomes invalid
' ==========================================================================

Private Sub TestBtn_Click()
Dim errcode, num, hic, i As Long
Dim cmddata(0 To 1024) As Byte ' command buffer
Dim buffer(0 To 512) As Byte ' user buffer

Dim line As String
Dim curline As Integer
Dim dwMaxCounter As Long
Const bufLen = 128


num = DIC_Find()
For i = 0 To num - 1
    hic = DIC_Open(i, 0&)
    If (hic >= 0) Then
        Exit For
    End If
Next i
If (i = num) Then
    Exit Sub
End If

' a. verify supper password
For i = 0 To 7
    cmddata(i) = 255
Next i
errcode = DIC_Command(hic, CHECK_SUPER_PASS, cmddata(0))

    'set the counter
   dwMaxCounter = 5
   errcode = DIC_Set(cmddata(0), 0, 4, dwMaxCounter, Null)
   errcode = DIC_Command(hic, SETCOUNTER, cmddata(0))
    

' i. cancel supper password status
errcode = DIC_Close(hic)
errcode = DIC_Open(hic, 0&)

    ' SET COUNTER
    List1.List(curline) = "STEPCOUNTER Test:"
        curline = curline + 1
        line = "success"
    For i = 0 To (dwMaxCounter)
    
        errcode = DIC_Command(hic, STEPCOUNTER, Null)
        If errcode <> SCARD_S_SUCCESS Then
            If (i >= dwMaxCounter) Then
                For j = 0 To 7
                    cmddata(j) = 255
                Next j
                errcode = DIC_Command(hic, CHECK_SUPER_PASS, cmddata(0))

                'set the counter
                dwMaxCounter = 0
                errcode = DIC_Set(cmddata(0), 0, 4, dwMaxCounter, Null)
                errcode = DIC_Command(hic, SETCOUNTER, cmddata(0))
                If (errcode <> SCARD_S_SUCCESS) Then
                    line = "failed"
                End If
            Else
                line = "failed"
                
            End If
        End If
    Next i
        
    List1.List(curline) = line
 

' m. close
errcode = DIC_Close(hic)

End Sub

