ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 5 3

7 ѹҤ ..2549
108 Users On-Line.
Visitors - Page views
 8 9 7 3 8 9 6
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ᨡ VB6 Ѻäӹdzѡ 15 Check Digit ͧ IMEI

Category »  VB 6/VB.Net
: Webmaster 29/12/2554   : 15:09
(ҹ : 23939) 
ҡǶ֧óդ (IMEI) С㴹ФѺ ҸͧԪҡôҹ ֧ԸաҤѡ 15 ͧ ѡǨͺ١ͧͧ 14 ѡá ( Mobile Phone) ... ѡǨͺ Check Digit ѹ੾ͧͧѾҹ ѧѺʺԹ 鴵˹ ͺѵûЪҪ觨ѡ 13 ѡǨͺ (ҹ´ ... ) ... ҷ֧ͧ Check Digit ͵Ǩͺ١ͧ ͻͧѹԴҴҡû͹Źͧ Ըա Check Digit ͧз Чҹѹᵡҧѹ͡ ... Ѻ⨷()͹¡ѹդʹ· ѹҾͧäԴ⨷͡ è¹ҹ鹡ѺѺ椹¤Ѻ ... ͧ
äԴ⨷

    Ըաѡ 15 ͧ IMEI ҡ 14 ѡá (¡Դѡ ѡ)
  1. óշѡ (ѡ 1, 3, 5, 7, 9, 11, 13) ӤѡͧѡҺǡѹ
      ҧ
    • ѡ 1 3
    • ѡ 3 8
    • ѡ 5 3
    • ѡ 7 0
    • ѡ 9 8
    • ѡ 11 3
    • ѡ 13 9
      ͧѡ 34
  2. óշѡ (ѡ 2, 4, 6, 8, 10, 12, 14) еͧӤѡҤٳ 2 ͹ ͹ѧ
    • ҡѡҤٳ 2 ӵͺŢѡ 仺ǡѺѡ
    • ҡѡҤٳ 2 ӵͺŢ 2 ѡ еͧ¡Ţ 2 ѡ͡Һǡѹ͹ Ǥ¹仺ǡѺѡ
      ҧ
    • ѡ 2 5 --> 5 x 2 = 10 --> (1 + 0) = 1
    • ѡ 4 4 --> 4 x 2 = 8
    • ѡ 6 9 --> 9 x 2 = 18 --> (1 + 8) = 9
    • ѡ 8 4 --> 4 x 2 = 8
    • ѡ 10 6 --> 6 x 2 = 12 --> (1 + 2) = 3
    • ѡ 12 2 --> 2 x 2 = 4
    • ѡ 14 7 --> 7 x 2 = 14 --> (1 + 4) = 5
      ͧѡ 38
  3. Ӽͧѡ ѡ Һǡѹ 蹤 34 + 38 = 72
  4. 鹵͹ش ѡ 15
      ԸաäԴѧ
    • ҡͧѡ+ѡŧ´¤ 0 70 Ҥ 0 繤ӵͺ (Check Digit ѡ 15)
    • ҡ ͧ͹Ҥҷŧ´ 0 Ѵ ¤ҷҧ͡仨ҡѡ+ѡ鹨繤ӵͺ
      Ѿ 55 ҷŧ´ 0 Ѵ令 60 ѧ 60 - 55 ӵͺ 5
      Ѿ 67 ҷŧ´ 0 Ѵ令 70 ѧ 70 - 67 ӵͺ 3
      㹵ҧ 80 - 72 ӵͺ 8
Ţ㹷 ŢӹǹǡФѺ
͹͸ԺͧäԴ¹ ͡ǾҴԧѧ»жС͹ФѺҹиҹþ ҷء¹ͧáѹ ҷŢӹǹѹշ駤ӵͺ (ŧɡ 0 ФѺͧ) 25 / 2 ӵͺ 12 1 33 / 3 ӵͺ 11 0 ... 㹴ҹѺдѺ٧ ѹẺ ѹö¡ǹ͡ҡѹ 2 (ͧѺ Visual Basic ФѺ ... ͧ)
  • \ (Կ) ẺѴ 25 \ 2 ӵͺ 12 ҹ еѴ͡
  • Mod (ʹ) Ẻ 25 Mod 2 ӵͺ 1
    СǶ֧Ȩ㨢ͧ Mod 蹤 Ҩӹǹ Mod (繵) ҵش 0 ٧ش ҷ Mod - 1
  • Mod 2 ӵͺ 0, 1
  • Mod 8 ӵͺ 0, 1, 2, 3, 4, 5, 6, 7
  • Mod 10 ӵͺ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    1. Ҵ١ѭТ
    2. Ҩҧ ѡҧ⨷ѹ˹ѹѡ ѡ (ҧҨй֧֡ǹٻ 2 ¡ѡ ѡ᷹) ... ;Ҵԧ»жաǤѺҹиҹ 55555+ Ţӹǹô 2 ŧ ( 0) ѹŢ ҡѹɡŢ ɷҹѹ 1 ҹ ԧ¤Ѻҹиҹ ... ҷҧûФѺ 蹤͡ùѡѡ Mod 2 ѧФѺ ... ͧ 55555+
    3. Ѻѡ Ҩ͹÷ͺҤҷٳ 2 ѹ 1 2 ѡ
        ҧѭ ...
      • Ѵͨӹǹѡͧҷ 蹤 IF Len() > 1
      • ҡѡ (Ţⴴ) դҵ 5 (5, 6, 7, 8, 9) ͤٳ 2 ǨзѾըӹǹ 2 ѡ 蹤 IF >= 5
      • èѴٻẺŢҴ 2 ѡ
    4. ѡ+ѡ ... ҡ͡Ƕ֧Ѻ
    5. Ҥӵͺѡ 15 ҡ ...
      • ҡҷҧشͧѡ+ѡ դ 0 ͺ 0
      • ҡ Ҥҷҧشͧѡ+ѡ ź͡ 10 ͤӵͺ
    Ǣͧ
    ᨡ Source Code ŢѵûЪҪ
    ǹŴ
    ǹŴ Source Code Ѻ MS Visual Basic 6.0

    Design Time


    Run Time
    Ҵ鴡ѹ ...
    
    Option Explicit
    
    Private Sub Form_Load()
        
        ' 駿觡ҧҾ
        Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
        
        ' ˹Ҩ
        Call SetupScreen
        
        ' ҧ
        txtFourteenDigit.Text = "35843904863297" ' <-- ӵͺ = 8
        'txtFourteenDigit.Text = "35780502398494" ' <-- ӵͺ = 2
        'txtFourteenDigit.Text = "358639048632965" ' <-- ӵͺ = 5
        'txtFourteenDigit.Text = "35688202005060" ' <-- ӵͺ = 6
    
    End Sub
    
    ' / -------------------------------------------------------------------------------------------------------------
    ' / 㹡˹Ҩ͡ʴ
    Sub SetupScreen()
    ' / -------------------------------------------------------------------------------------------------------------
        txtFourteenDigit.Text = ""
        txtCheckDigit.Text = ""
        txtIMEI.Text = ""
    End Sub
    
    ' / -------------------------------------------------------------------------------------------------------------
    ' ꡻ͷӡäӹdz Check Digit ѡ 15 ͧ IMEI 14 ѡá
    Private Sub cmdCal_Click()
    ' / -------------------------------------------------------------------------------------------------------------
        Dim i As Integer
        ' ӹǹ 14 ѡ
        Dim Digit As Byte
        ' ѡ
        Dim SumOdd As Integer
        ' ѡ
        Dim SumEven As Integer
        ' ѡǡѡ
        Dim Sum14Digit As Integer
        ' ǤǢͧäٳ 2 ѡ
        Dim EvenTemp As Integer
        
        ' ǨͺŢӹǹ 14 ѡáһ͹Ҥú
        If Trim(txtFourteenDigit.Text) = "" Or Len(Trim$(txtFourteenDigit.Text)) < 14 Then
            MsgBox "سһ͹Ţ 14 ѡáͧ IMEI ú͹.", _
            	vbOKOnly + vbExclamation, "§ҹԴҴ"
            Exit Sub
        End If
        
        ' ǹͺ 14 駨ҡ 14 ѡáͧ IMEI
        For Digit = 1 To Len(txtFourteenDigit.Text)
            
            ' ҡѾ 0 ʴѡ ҨҾԨóѡٳ 2 
            If (Digit Mod 2) = 0 Then
            
                ' Mid$(Val(txtFourteenDigit.Text), Digit, 1) * 2 ѡҤٳ 2
                ' ѾҨѴ§Ţ 2 ѡ
                ' Right$("00" & Mid$(Val(txtFourteenDigit.Text), Digit, 1) * 2, 2)
                '  ҡ 8 ...  "00" ʹ "8" Ѿ "008"
                ' Ѻҡ 2 ѡ Ѿ "08"
                EvenTemp = Right$("00" & Mid$(Val(txtFourteenDigit.Text), Digit, 1) * 2, 2)
                
                ' Ӥ 2 ѡҡԾҧҹҺǡѹ еͧǡҡѺѡ 
                ' óѡ 2 ǡѺ 0 ( SumEven)
                ' óѡ 4 ǹͺѡ Һǡ仡Ѻ (SumEven) 2  
                ' (ص) SumEven դҡѺ 1 ǹŨҡäٳ 2 ѡ 4 դҡѺ 08
                ' ͺá SumEven = 1 + 0 ҡѺ 1
                ' ͺͧ SumEven = 1 + 8 ҡѺ 9
                ' ¤Ѻͧ ... 55555+
                For i = 1 To 2
                     SumEven = SumEven + Val(Mid$(EvenTemp, i, 1))
                Next
                
                ' ҧաǤԴ͹Ҫ
                'EvenTemp = Val(Mid(txtFourteenDigit.Text, Digit, 1)) * 2
                ' ԸաùѺǢͧŤٳѡ (͡ IF 㴵ǹ֧ФѺ)
                'If Len(EvenTemp) > 1 Then
                '  Ҥҷ >= 5 ͹
                'If Mid$(txtFourteenDigit, Digit, 1) >= 5 Then
                '    For i = 1 To 2
                '        SumEven = SumEven + Val(Mid$(CStr(EvenTemp), i, 1))
                '    Next
                'Else
                '    SumEven = SumEven + EvenTemp
                'End If
                
            ' ҡɼѾ 1 ʴѡ
            Else
                ' úǡͧѡѡ ѹ˹ ֧͸Ժ¹ФѺͧ
                SumOdd = SumOdd + Mid$(Val(txtFourteenDigit.Text), Digit, 1)
            End If
            
            ' öŢͧѡ ѡç¡ ¡͡仨ҡ Loop For ФѺ
            ' ͧ繧
        
        Next
        
        ' ѡѡ
        Sum14Digit = SumOdd + SumEven
        
        ' / -------------------------------------------------------------------------------------------------------------
        ' Ҥѡ 15  ѡǨͺ١ͧ (Check Digit) ͧ ѡôѧ
        ' 1. ҡͧѡѡѹŧ´ 0  0 繤ӵͺ·ѹ
        ' 2. ҡ ͧ͹Ҥҷŧ´ 0 Ѵ Ҥҷҧѹ繤ӵͺ 
        ' Ѿ 55 ҷŧ´ 0 Ѵ令 60 ѧ 60 - 55 ӵͺ 5
        ' Ѿ 67 ҷŧ´ 0 Ѵ令 70 ѧ 70 - 67 ӵͺ 3
        ' ҹ͡äԴҤҴ ѭҡͨ¹͡ѧ ...
        ' ҡҵҧ 55  67 Ҩ еͧѡش 5  7 ͡
        ' Ҩ Right ش 1 ǡ ź͡ 10 ͤӵͺ
        ' Դ͡ Mod (ա)
        '  Mod  10 ѧФѺ С Mod  10 зդҧ 0 - 9
        '  55 Mod 10  5  67 Mod 10  7
        ' ǹӤҹź͡ҡ 10 繤ӵͺ  10 - 5 = 5  10 - 7 = 3
        ' ҨФԴẺ˹ ͹ŧ¹ 繨еͧդصͷӡ÷ͺ͹
        ' / -------------------------------------------------------------------------------------------------------------
        
        ' ͡Ẻ ѧ鹨֧դ繵ͧ¹͹
        ' տѧ (ͤ) Right ҴѡҤѡش ҡóռѡѡŧ´ 0
        ' ҡҧ 14 ѡá = 35843904863297
        ' ͧ Sum14Digit = 72 ... 蹤 72 Mod 10 = 2
        ' 10 - 2 = 8 <-- ͤӵͺͧѡ 15
        txtCheckDigit.Text = Right$(10 - Sum14Digit Mod 10, 1)
        ' 繵ͧǧ  Mod ӴѺӤѭ٧ҡź ֧ͧӡ Mod ͹
        
        ' ͡Шº÷Ѵ͹ͧ͡繧
        'If Sum14Digit Mod 10 = 0 Then
        '    txtCheckDigit.Text = 0
        
        ' ҡ Mod  0 ͹Ҥҷٹͷ¶Ѵ ź͡ 10
        'Else
        '    txtCheckDigit.Text = (10 - Sum14Digit Mod 10)
        'End If
        
        ' / -------------------------------------------------------------------------------------------------------------
        ' ҤҷҨѴ§繤ӵͺش
        txtIMEI.Text = txtFourteenDigit.Text & txtCheckDigit.Text
        ' / -------------------------------------------------------------------------------------------------------------
        
    End Sub
    
    ' / -------------------------------------------------------------------------------------------------------------
    ' / Ǩͺá TextBox ੾еŢ 0 - 9
    ' / Index ͤ ASCII Code ͧ Character е
    Function CheckDigitOnly(Index As Integer) As Integer
    ' / -------------------------------------------------------------------------------------------------------------
        Select Case Index
            ' 0 - 9
            Case 48 To 57
            ' Back Space
            Case 8
            ' Enter
            Case 13
            ' ͧö ׹ҡѺ 0 ͹աá
            Case Else
                Index = 0
        End Select
        CheckDigitOnly = Index
    End Function
    
    Private Sub txtFourteenDigit_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
            KeyAscii = 0
            Call cmdCal_Click
        Else
            KeyAscii = CheckDigitOnly(KeyAscii)
        End If
    End Sub
    
    Conclusion:
    ⨷͹ҧѴਹ ¤дѺ鹰ҹ鹻жҪ㹡ѭҹͧѺ äԴ⨷ (Ҥӵͺ¡äӹdz) ǼҹѺ觾ͧе ... ҷ 觤آʴջ͹ͧͧءҹѺ


    ͵ - g2gNet Dot Com
    Ţ¹ҳԪ硷͹ԡ 0407314800231
    CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
    Email: [email protected] . 08-6862-6560