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

͵Դҷҧ 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 4 6

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

Google   
g2gnet.com
Ҵѡ:  

ᨡ Source Code ŢѵûЪҪ

Category »  VB 6/VB.Net
: Webmaster 7/5/2553   : 12:02
(ҹ : 32861) 
ǢẺ ¤ԴҼʹѺʹع餹ӼԴ ¡ûŧŢѵûЪҪ ¤Ѻ ... س仵Դͧҹ¹ ӸáҧԹ ¹ŢѾ سͧӺѵûЪҪǨԧ Ҿ͡áӡѺ й仴·ء ѹкŢѵûЪҪ᷹ 55555+ ԧ¤Ѻ ... ͤԴҼʹѺʹعŢѵûЪҪ ͹Ѥ͹Ź ... ׹仾ٴẺѺ ѧⴹǹѺФѺ " ҹ () ѧ ҵ䫵" (硡 ¡١Ңͧѷԡҧ) ... ѧ觷й¹繺 ͧͧý֡¹ (֡ФѺ) ѹ⨷ҡ㹡ý֡Դ Algorithm á (Logic) ͧͧ Algorithm ¹ (͹ҢẺҡҡ) ǹͧá йͧѺ
    ѡäӹdzŢѵûЪҪ
  • Ţҷ 12 ѡ ·ѡáͧŢ 0 Ţ 9 ... ǹФѺǹӤѭ ҡͧءҹ ¹Ѻͧͧ á (Logic) ѹ§ 2 ԧ (TRUE) Ѻ (FALSE) ... ͧѹ͹ ФѺ Ҩԧ ѹ´ҧԴ (ͧͺ¹ͧ͹仴鴡Ѻ) ... ѡɳẺ繡÷ӫ (Repetitive) ¤觨Ӿǡ While, Do While, Do Until, Do Loop While Do Loop Until ( FOR 㹡ѭ ... ͧԴͧѺ) ... ⨷͹ͧöͧҾᵡҧҧǹͺ (Loop) Ẻ FOR ÷ӫ (Repetitive) ҧѴਹ·
    
    ٻẺ
    Do { While | Until } condition
        [ statements ]
        [ Exit Do ]
        [ statements ]
    Loop
    --
    Do
        [ statements ]
        [ Exit Do ]
        [ statements ]
    Loop { While | Until } condition
    ҹ´ ҡ觢ҧԧ
    ͧͧ ͹ Condition ö ԧ 㹡÷ӫ ѹѺ ͡͹Ẻ˹ Ѻ ... ͧ ͧҡҵŢѡáͧ 0 Ѻ 9 ѧѹ֧ͧ͹䢢ͧ AND/OR NOT ҹ ... ֧ͧͧ ҧҤԧ Truth Table (觼¹ҵ Ǫ. 硷͹ԡ) ͹ʴ繡ѹ ... ͧҧǤѺ ͧӤ֡ Чҹ¹ԧ繵ͧҹҡ
    ҧҤԧ Truth Table (Ѻҧ AND/OR Input 2 A B)

    A

    B

    A AND B

    FALSE

    FALSE

    FALSE

    FALSE

    TRUE

    FALSE

    TRUE

    FALSE

    FALSE

    TRUE

    TRUE

    TRUE

    A

    B

    A OR B

    FALSE

    FALSE

    FALSE

    FALSE

    TRUE

    TRUE

    TRUE

    FALSE

    TRUE

    TRUE

    TRUE

    TRUE

    A

    NOT A

    FALSE

    TRUE

    TRUE

    FALSE

  • ػѹҨ Input ҡǡ
    • óա AND () ... ҡ Input 1 False ӵͺ False
    • óա OR () ... ҡ Input 1 True ӵͺ True
  • ӹdzҼͧŢ 12 ѡ (͸Ժǹͧ)
  • ӹdzŢѡ 13 ѡǨͺ Check Digit ó
ǹŴ Source Code Ѻҹ Visual Basic 6
ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack
 ǹŴ Microsoft Data Access Object (MDAC) Jet 4.0 Update
 ǹŴ Microsoft Visual Basic Service Pack 6
ǹŴѺͧҧ
ǹŴŢѵûЪҪ - Random IDCard.exe
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack (ҡöѹ Random ICCard.exe ǹŴ Run-Time ǹ仵Դ駴¤Ѻ)

Source Code õǨͺŢѵûЪҪ (VB6 + VB.Net)

ŢѵûЪҪ

鹡кǹ÷ӧҹ

Option Explicit

Sub SetupScreen()
    txtRandomNumber.Text = ""
    txtCheckDigit.Text = ""
    txtIDCard.Text = ""
End Sub

' ########################################################
' ꡻ͷӡŢѵûЪҪ
Private Sub cmdRandom_Click()
' ########################################################
Dim Sum As Integer
Dim Count As Byte
    
    Call SetupScreen
    
    ' ҵŢҷ 12 ѡ ·ѡáͧ 0  9 
    ' ¡ѧѧ RandomNumber ա觤 еͧѺҷѺ
    txtRandomNumber.Text = RandomNumber
    
    ' ѡԴѺ 12 ѡá
    ' 鹤ӹdzҤҼŢ 12 ѡá ѧ
    ' Ҽѡ 1 仨֧ѡ 12 (Ѻҡ仢)
    ' ѡ 1 ٳ¹˹ѡШѡ = 13
    ' ѡ 2 ٳ¹˹ѡШѡ = 12
    ' ѡ 3 ٳ¹˹ѡШѡ = 11
    ' ѡ .. ٳ¹˹ѡШѡ = ..
    ' ѡ 12 ٳ¹˹ѡШѡ = 2
    ' ҡ鹹Ӽšäٳͧѡѹ

    ' ѡѡ  Val(Mid$(txtIDcard.Text, Count, 1))
    ' ˹ѡͧѡ  (14 - Count)  Count 鹨ҡ 1 ش 12
    ' ѧ鹤ҹ (14 - Count) ֧鹤Ҩҡ 13, 12, 11, ..., ش 2 Ѻ
    Sum = 0 ' Clear Ҽ͹ (ͤ)
    For Count = 1 To 12
        Sum = Sum + Val(Mid$(txtRandomNumber.Text, Count, 1)) * (14 - Count)
    Next
    
    ' ########################################################
    ' 鹵͹  Ҥ Check Digit  ѡǨͺ١ͧ
    ' Ӽ (Sum)  Mod ()  11 蹤ͤҷҨ 0, 1, 2, .. , 10 (Sum Mod 11)
    ' ҡź͡ 11 зҵ 1, 2, 3, ... , 11 (11 - (Sum Mod 11))
    ' ͡Ǣش˹觵 ¤ Right$ --> Right$(Str(11 - Sum Mod 11)), 1)
    ' ش¹ ѡ 13  ѡǨͺ١ͧ (Check Digit) ͧ
    '
    txtCheckDigit.Text = Right$(Str(11 - (Sum Mod 11)), 1)
    '
    ' ########################################################
    
    ' ########################################################
    ' ҤҨѴ§͹㹡Ѥ ... 55555+
    '
    txtIDCard.Text = txtRandomNumber.Text & txtCheckDigit.Text
    '
    ' ########################################################
    
End Sub

' ########################################################
' ѧ蹷㹡Ţӹǹ 12 ѡ աѺ еͧ觤Ҥ׹Ѻ (Return)
' ѧҵͧẺѧ (Function)  Sub Program 
'
Function RandomNumber() As String
'
' ########################################################
' ͺ觺͡ѡáҤ
Dim blnFlag As Boolean
Dim i As Byte
    
    ' 㹡Ţ͹
    Randomize
    
    ' ٵáŢ  High = ٧ش  Low = ҵش
    'RandomNumber = Int((High - Low + 1) * Rnd) + Low
    
    ' 駤 False ͹
    blnFlag = False
    
    ' Ţӹǹ 12 ѡ ·ѡáͧ 0  9
    ' ͧҡùѺ鹨ҡ 1 ش 12 դ鹷 1 ...  For
    For i = 1 To 12
        ' Not False  ԧ   (¹ blnFlag = False) ... ʴҵ͹ҡѧҵŢѡá
        If Not blnFlag Then
            ' Ţѡá ͧդ 0  9 ... ͡÷ӫ  Repetitive
            ' ǹͺ (Loop) Ẻ For Ѻҹ  ش   (Ŵ)
            ' ѹ͹ѹФѺ ѹդ͡ҡ Loop  Exit For 
            Do
                
                ' ǡ 0 ź 0  ... 
                RandomNumber = Int((9 - 0 + 1) * Rnd) + 0
                
            ' ӨѡáͧҡѺ 0  9 (͹䢵ͧ AND)
            '   RandomNumber դ = 1
            ' ͹ 1 <> 0  1 <> 9 (True AND True = True) ... ͹ "ԧ" ͡ҡ Loop
            '   RandomNumber դ = 9
            ' ͹ 9 <> 0  9 <> 9 (True AND False = False) ... ͹ "" ǹ Loop 
            Loop Until RandomNumber <> 0 And RandomNumber <> 9
            
            '  ͹ Until Ѻѹ Not ... ¹Ẻǹ˭繾ǡдѺҪվѺ ... 
            'Loop Until Not RandomNumber = 0 And Not RandomNumber = 9
            
            '  While ͹䢵ͧѺѹѺẺ Until еͧ OR ᷹
            '   RandomNumber դ = 1
            ' ͹ 1 = 0  1 = 9 (False OR False = False) ... ͹ "" ͡ҡ Loop
            '   RandomNumber դ = 9
            ' ͹ 9 = 0  9 = 9 (False OR True = True) ... ͹ "ԧ" ǹ Loop 
            'Loop While RandomNumber = 0 Or RandomNumber = 9
            
            ' ѡáҵŢ 0  9 ó ѡ仨ͧ Do Loop ա
            blnFlag = True
        End If
        
        ' ҤҨӹǹѡ 觤Ҥ׹Ѻͧѧ
        RandomNumber = RandomNumber & Int((9 - 0 + 1) * Rnd) + 0
    Next

End Function

Private Sub Form_Load()
    ' ͧѹ¡
    If App.PrevInstance Then End
    
    ' 駿觡ҧҾ
    Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
    
    Call SetupScreen

End Sub
Conclusion:
⨷ҡҡ¹ѡ§ ö¹ѡ¹ҧ ѧ鹾ͧѴѴѺ ͧ÷ѹǹФѺ ͹ҽ֡Դ ֡ ¹ (͡) ˹ѧ ͧѹͺ Ǿѹҹ Ѻ֡ѡԴͧ ¹ ѹѧ͡Ѻ ... ͧ ... Ѻ ѴԴ͹Ѻ ¡¹ѧҹ Flowchart ٷիԤѺ ͷͺᴧ˹ѹ ... ͼͧ¤Ѻ

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