www.pudn.com > feijiechu_IC_card_reader.rar > Module1.bas


Attribute VB_Name = "Module1" 
 Declare Function OpenComm Lib "mifdll.dll" (ByVal nPort As Integer) As Integer 
 Declare Function CloseComm Lib "mifdll.dll" () As Integer 
 Declare Function GetState Lib "mifdll.dll" (ByVal nPort As Integer) As Integer 
 
 Declare Function mif_request Lib "mifdll.dll" (ByVal mode As Byte) As Integer 
 Declare Function mif_anticoll Lib "mifdll.dll" (ByVal bcnt As Byte, ByRef nSnr As Long) As Integer 
 Declare Function mif_select Lib "mifdll.dll" (ByVal nSnr As Long, ByRef nSize As Byte) As Integer 
 Declare Function mif_load_key Lib "mifdll.dll" (ByVal mode As Byte, ByVal key_addr As Byte, ByVal transportkey As String, ByVal newkey As String) As Integer 
 
 Declare Function mif_authentication Lib "mifdll.dll" (ByVal mode As Byte, ByVal sector_nr As Byte) As Integer 
 Declare Function mif_authentication_2 Lib "mifdll.dll" (ByVal mode As Byte, ByVal key_nr As Byte, ByVal adr As Byte) As Integer 
 Declare Function mif_read Lib "mifdll.dll" (ByVal adr As Byte, ByVal readdata As String) As Integer 
 Declare Function mif_write Lib "mifdll.dll" (ByVal adr As Byte, ByVal writedata As String) As Integer 
 Declare Function mif_check_write Lib "mifdll.dll" (ByVal snr As Long, ByVal authmode As Byte, ByVal adr As Byte, ByVal writedata As String) As Integer 
 Declare Function mif_initval Lib "mifdll.dll" (ByVal adr As Byte, ByVal value As Long) As Integer 
 Declare Function mif_increment Lib "mifdll.dll" (ByVal adr As Byte, ByVal value As Long) As Integer 
 Declare Function mif_decrement Lib "mifdll.dll" (ByVal adr As Byte, ByVal value As Long) As Integer 
 Declare Function mif_restore Lib "mifdll.dll" (ByVal adr As Byte) As Integer 
 Declare Function mif_transfer Lib "mifdll.dll" (ByVal adr As Byte) As Integer 
 Declare Function mif_halt Lib "mifdll.dll" () As Integer 
 Declare Function mif_reset Lib "mifdll.dll" (ByVal msec As Byte) As Integer 
 Declare Function mif_request_2 Lib "mifdll.dll" (ByVal mode As Byte, ByRef tt As Integer) As Integer 
Public Function NumToChar(ByVal nNum As Byte) As String 
    If (nNum >= 0 And nNum <= 9) Then 
        NumToChar = Chr(nNum + 48) 
    End If 
    If (nNum >= 10 And nNum < 16) Then 
        NumToChar = Chr(nNum + 55) 
    End If 
End Function 
Public Function CharToNum(inChar As String) As Byte 
    Select Case UCase(inChar) 
        Case "0" To "9": CharToNum = CByte(inChar) 
        Case "A" To "F": CharToNum = Asc(UCase(inChar)) - 55 
        Case Else:       CharToNum = 0 
    End Select 
End Function 
Public Function ValidText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer 
    Dim ValidateList As String 
    Dim KeyOut As Integer 
    If Editable = True Then 
         ValidateList = UCase(ValidateString) & Chr(8) 
    Else 
         ValidateList = UCase(ValidateString) 
    End If 
    If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then 
        KeyOut = KeyIn 
    Else 
        KeyOut = 0 
        Beep 
    End If 
    ValidText = KeyOut 
End Function