VERSION 5.00
Begin VB.Form frmMain 
   Caption         =   "Form1"
   ClientHeight    =   5520
   ClientLeft      =   120
   ClientTop       =   420
   ClientWidth     =   10320
   LinkTopic       =   "Form1"
   ScaleHeight     =   5520
   ScaleWidth      =   10320
   StartUpPosition =   3  'Windows 기본값
   Begin VB.Frame Frame3 
      Caption         =   "3) Read && write block"
      Height          =   2295
      Left            =   120
      TabIndex        =   24
      Top             =   2760
      Width           =   10095
      Begin VB.Frame Frame5 
         Caption         =   "Command"
         Height          =   975
         Left            =   5520
         TabIndex        =   46
         Top             =   360
         Width           =   4335
         Begin VB.CommandButton cmdWriteBlock 
            Caption         =   "Write Block"
            Height          =   375
            Left            =   2520
            TabIndex        =   48
            Top             =   360
            Width           =   1335
         End
         Begin VB.CommandButton cmdReadBlock 
            Caption         =   "Read Block"
            Height          =   375
            Left            =   720
            TabIndex        =   47
            Top             =   360
            Width           =   1335
         End
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   15
         Left            =   9240
         TabIndex        =   45
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   14
         Left            =   8640
         TabIndex        =   44
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   13
         Left            =   8040
         TabIndex        =   43
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   12
         Left            =   7440
         TabIndex        =   42
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   11
         Left            =   6840
         TabIndex        =   41
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   10
         Left            =   6240
         TabIndex        =   40
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   9
         Left            =   5640
         TabIndex        =   39
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   8
         Left            =   5040
         TabIndex        =   38
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   7
         Left            =   4440
         TabIndex        =   37
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   6
         Left            =   3840
         TabIndex        =   36
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   5
         Left            =   3240
         TabIndex        =   35
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   4
         Left            =   2640
         TabIndex        =   34
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   3
         Left            =   2040
         TabIndex        =   33
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   2
         Left            =   1440
         TabIndex        =   32
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   1
         Left            =   840
         TabIndex        =   31
         Top             =   1680
         Width           =   495
      End
      Begin VB.TextBox txtBlockData 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   0
         Left            =   240
         TabIndex        =   30
         Top             =   1680
         Width           =   495
      End
      Begin VB.Frame Frame4 
         Caption         =   "Block address"
         Height          =   975
         Left            =   240
         TabIndex        =   25
         Top             =   360
         Width           =   5055
         Begin VB.TextBox txtBlockNum 
            Height          =   270
            Left            =   3360
            TabIndex        =   29
            Text            =   "0"
            Top             =   480
            Width           =   855
         End
         Begin VB.TextBox txtSectorNum 
            Height          =   270
            Left            =   1200
            TabIndex        =   28
            Text            =   "0"
            Top             =   480
            Width           =   855
         End
         Begin VB.Label Label2 
            Caption         =   "Block #:"
            Height          =   255
            Left            =   2520
            TabIndex        =   27
            Top             =   480
            Width           =   975
         End
         Begin VB.Label Label1 
            Caption         =   "Sector #:"
            Height          =   255
            Left            =   240
            TabIndex        =   26
            Top             =   480
            Width           =   975
         End
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "2) Key Info."
      Height          =   2535
      Left            =   5640
      TabIndex        =   8
      Top             =   120
      Width           =   4575
      Begin VB.OptionButton radioKeyB 
         Caption         =   "Use Key B"
         Height          =   180
         Left            =   480
         TabIndex        =   23
         Top             =   1440
         Width           =   3015
      End
      Begin VB.OptionButton radioKeyA 
         Caption         =   "Use Key A"
         Height          =   180
         Left            =   480
         TabIndex        =   22
         Top             =   360
         Value           =   -1  'True
         Width           =   3015
      End
      Begin VB.TextBox txtKeyB 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   5
         Left            =   3600
         TabIndex        =   21
         Top             =   1800
         Width           =   495
      End
      Begin VB.TextBox txtKeyB 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   4
         Left            =   3000
         TabIndex        =   20
         Top             =   1800
         Width           =   495
      End
      Begin VB.TextBox txtKeyB 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   3
         Left            =   2400
         TabIndex        =   19
         Top             =   1800
         Width           =   495
      End
      Begin VB.TextBox txtKeyB 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   2
         Left            =   1800
         TabIndex        =   18
         Top             =   1800
         Width           =   495
      End
      Begin VB.TextBox txtKeyB 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   1
         Left            =   1200
         TabIndex        =   17
         Top             =   1800
         Width           =   495
      End
      Begin VB.TextBox txtKeyB 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   0
         Left            =   600
         TabIndex        =   16
         Top             =   1800
         Width           =   495
      End
      Begin VB.TextBox txtKeyA 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   5
         Left            =   3600
         TabIndex        =   15
         Top             =   720
         Width           =   495
      End
      Begin VB.TextBox txtKeyA 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   4
         Left            =   3000
         TabIndex        =   14
         Top             =   720
         Width           =   495
      End
      Begin VB.TextBox txtKeyA 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   3
         Left            =   2400
         TabIndex        =   13
         Top             =   720
         Width           =   495
      End
      Begin VB.TextBox txtKeyA 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   2
         Left            =   1800
         TabIndex        =   12
         Top             =   720
         Width           =   495
      End
      Begin VB.TextBox txtKeyA 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   1
         Left            =   1200
         TabIndex        =   11
         Top             =   720
         Width           =   495
      End
      Begin VB.TextBox txtKeyA 
         Alignment       =   2  '가운데 맞춤
         BackColor       =   &H00000000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Index           =   0
         Left            =   600
         TabIndex        =   10
         Top             =   720
         Width           =   495
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "1) Device select"
      Height          =   2535
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5295
      Begin VB.CommandButton cmdRFPowerON 
         Caption         =   "RF Power On"
         Height          =   375
         Left            =   1800
         TabIndex        =   9
         Top             =   1320
         Width           =   1575
      End
      Begin VB.CommandButton cmdReadSerial 
         Caption         =   "Read Serial"
         Height          =   375
         Left            =   240
         TabIndex        =   6
         Top             =   1920
         Width           =   1335
      End
      Begin VB.CommandButton cmdRFPowerOff 
         Caption         =   "RF Power Off"
         Height          =   375
         Left            =   3480
         TabIndex        =   5
         Top             =   1320
         Width           =   1575
      End
      Begin VB.ComboBox comboDevice 
         Height          =   300
         Left            =   1320
         Style           =   2  '드롭다운 목록
         TabIndex        =   2
         Top             =   360
         Width           =   3735
      End
      Begin VB.CommandButton btnSelect 
         Caption         =   "Select"
         Height          =   375
         Left            =   3840
         TabIndex        =   1
         Top             =   720
         Width           =   1215
      End
      Begin VB.Label labelSerial 
         BorderStyle     =   1  '단일 고정
         Height          =   375
         Left            =   1800
         TabIndex        =   7
         Top             =   1920
         Width           =   3255
      End
      Begin VB.Line Line3 
         BorderColor     =   &H8000000A&
         X1              =   240
         X2              =   5160
         Y1              =   1800
         Y2              =   1800
      End
      Begin VB.Label Label8 
         Caption         =   "Device ID:"
         Height          =   255
         Left            =   240
         TabIndex        =   3
         Top             =   360
         Width           =   975
      End
      Begin VB.Line Line2 
         BorderColor     =   &H8000000A&
         X1              =   240
         X2              =   5160
         Y1              =   1200
         Y2              =   1200
      End
   End
   Begin VB.Label labelStatus 
      Appearance      =   0  '평면
      BackColor       =   &H80000005&
      BorderStyle     =   1  '단일 고정
      Caption         =   "Label1"
      ForeColor       =   &H80000008&
      Height          =   375
      Left            =   0
      TabIndex        =   4
      Top             =   5160
      Width           =   10335
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Declaration global variables
Dim WithEvents objUCBioBSP As UCBioBSPCOMLib.UCBioBSP
Attribute objUCBioBSP.VB_VarHelpID = -1

Dim objDevice As IDevice                ' Device object
Dim objSmartCard As ISmartCard          ' SmartCard object

Private Sub SetAuthModeAndKey()
    Dim key(6) As Byte
    
    If radioKeyA.Value Then
        For i = 0 To 5
            strHex = "&H" & txtKeyA(i).Text
            key(i) = CByte(strHex)
        Next
        
        objSmartCard.AuthMode = &H60      ' 0x60 - Use Key A
        objSmartCard.KeyA = key
    Else
        For i = 0 To 5
            strHex = "&H" & txtKeyB(i).Text
            key(i) = CByte(strHex)
        Next
        
        objSmartCard.AuthMode = &H61      ' 0x61 - Use Key B
        objSmartCard.KeyB = key
    End If
    
    objSmartCard.LED = 1    ' toggle LED
    
End Sub
Private Sub btnSelect_Click()
    ' Select device type
    nNameID = 0
    If comboDevice.ListIndex > 0 Then
        nNameID = objDevice.EnumDeviceNameID(comboDevice.ListIndex - 1)
    End If
    
    If comboDevice.ListIndex > 0 Then
        iDeviceID = objDevice.DeviceID(nNameID, objDevice.EnumDeviceInstance(comboDevice.ListIndex - 1))
    Else
        iDeviceID = &HFF 'Auto
    End If
    
    ' Close Device if before opened
    Call objDevice.Close(objDevice.OpenedDeviceID)
    
    ' Open device
    Call objDevice.Open(iDeviceID)
    
    If objUCBioBSP.ErrorCode = 0 Then
        labelStatus.Caption = "Succeeded to open device."
        
        If comboDevice.ListIndex > 0 Then
            nNameID = objDevice.EnumDeviceNameID(comboDevice.ListIndex - 1)
            If nNameID <> 0 Then
                labelStatus.Caption = labelStatus.Caption & " - " & objDevice.EnumDeviceDescription(comboDevice.ListIndex - 1)
            End If
            
        Else
            labelStatus.Caption = labelStatus.Caption & " - " & "Auto Detect Device"
        End If
    Else
        labelStatus.Caption = "Failed to open device! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
    
End Sub

Private Sub cmdReadBlock_Click()
    Dim blockData() As Byte
    
    Call SetAuthModeAndKey
    
    objSmartCard.ReadBlock CLng(txtSectorNum.Text), CLng(txtBlockNum.Text)
    
    If objUCBioBSP.ErrorCode = 0 Then
        blockData = objSmartCard.ResultBuffer
        
        For i = 0 To 15
            txtBlockData(i).Text = ""
        Next i
        
        For i = 0 To UBound(blockData)
            strHex = Hex$(blockData(i))
            If Len(strHex) = 1 Then
                strHex = "0" + strHex
            End If
                
            txtBlockData(i).Text = strHex
        Next i
        
        labelStatus.Caption = "Succeeded to read block!"
    Else
        labelStatus.Caption = "Failed to read block! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
   
End Sub

Private Sub cmdReadSerial_Click()
    Dim serial() As Byte
    
    objSmartCard.ReadSerial
    
    If objUCBioBSP.ErrorCode = 0 Then
        serial = objSmartCard.ResultBuffer
        labelSerial.Caption = Str$(objSmartCard.serial) + " (" + Hex$(serial(0)) + " " + Hex$(serial(1)) + " " + Hex$(serial(2)) + " " + Hex$(serial(3)) + ")"
        labelStatus.Caption = "Succeeded to read serial!"
    Else
        labelStatus.Caption = "Failed to read serial! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
End Sub

Private Sub cmdRFPowerOff_Click()
    objSmartCard.RFPowerOff
    
    If objUCBioBSP.ErrorCode = 0 Then
        cmdReadBlock.Enabled = False
        cmdWriteBlock.Enabled = False
        labelStatus.Caption = "Succeeded to RFPowerOff!"
    Else
        labelStatus.Caption = "Failed to RFPowerOff! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
End Sub

Private Sub cmdRFPowerON_Click()
    objSmartCard.RFPowerOn
    
    cmdReadBlock.Enabled = False
    cmdWriteBlock.Enabled = False
    
    If objUCBioBSP.ErrorCode = 0 Then
        cmdReadBlock.Enabled = True
        cmdWriteBlock.Enabled = True
        labelStatus.Caption = "Succeeded to RFPowerOn!"
    Else
        labelStatus.Caption = "Failed to RFPowerOn! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
End Sub

Private Sub cmdWriteBlock_Click()
    Dim blockData(16) As Byte
    
    For i = 0 To 15
        strHex = "&H" & txtBlockData(i).Text
        blockData(i) = CByte(strHex)
    Next i
    
    objSmartCard.WriteBlock CLng(txtSectorNum.Text), CLng(txtBlockNum.Text), blockData
    
    If objUCBioBSP.ErrorCode = 0 Then
        labelStatus.Caption = "Succeeded to write block!"
    Else
        labelStatus.Caption = "Failed to write block! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
End Sub

Private Sub Form_Load()
    ' Create UCBioBSP object
    Set objUCBioBSP = New UCBioBSPCOMLib.UCBioBSP
    Set objDevice = objUCBioBSP.Device
    Set objSmartCard = objUCBioBSP.SmartCard
    
    ' Check initialize object
    If objUCBioBSP.ErrorCode = 0 Then
        ' Get UCBioBSP version
        frmMain.Caption = "VB Sample - UCBioBSPCOM_SmartCardDemoVB Version : " & objUCBioBSP.MajorVersion & "." & objUCBioBSP.MinorVersion

        ' Enumerate Device
        Dim i As Integer
    
        Call objDevice.Enumerate
        labelStatus.Caption = objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    
        comboDevice.AddItem "Auto_Detect"
        For i = 0 To objDevice.EnumCount - 1
            nNameID = objDevice.EnumDeviceNameID(i)
            If nNameID <> 0 Then
                comboDevice.AddItem objDevice.EnumDeviceName(i) & " - " & objDevice.EnumDeviceDescription(i)
            End If
        Next i
        
        comboDevice.ListIndex = 0
        
        Call btnSelect_Click
    Else
        MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly
    End If
    
    For i = 0 To 5
        txtKeyA(i).Text = "FF"
        txtKeyB(i).Text = "FF"
    Next
    
    cmdReadBlock.Enabled = False
    cmdWriteBlock.Enabled = False
End Sub

Private Sub txtKeyA_Change(Index As Integer)
    If Len(txtKeyA(Index).Text) > 2 Then
        txtKeyA(Index).Text = Left$(txtKeyA(Index).Text, 2)
    End If
    
    txtKeyA(Index).Text = UCase$(txtKeyA(Index).Text)
End Sub

Private Sub txtKeyB_Change(Index As Integer)
    If Len(txtKeyB(Index).Text) > 2 Then
        txtKeyB(Index).Text = Left$(txtKeyB(Index).Text, 2)
    End If
    
    txtKeyB(Index).Text = UCase$(txtKeyB(Index).Text)
End Sub
